forked from csc-training/advanced-mpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpi-io.c
57 lines (43 loc) · 1.33 KB
/
mpi-io.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <mpi.h>
#define DATASIZE 64
#define WRITER_ID 0
void mpiio_writer(int, int *, int);
int main(int argc, char *argv[])
{
int my_id, ntasks, i, localsize;
int *localvector;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &ntasks);
MPI_Comm_rank(MPI_COMM_WORLD, &my_id);
if (ntasks > 64) {
fprintf(stderr, "Datasize (64) should be divisible by number "
"of tasks.\n");
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
if (DATASIZE % ntasks != 0) {
fprintf(stderr, "Datasize (64) should be divisible by number "
"of tasks.\n");
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
localsize = DATASIZE / ntasks;
localvector = (int *) malloc(localsize * sizeof(int));
for (i = 0; i < localsize; i++) {
localvector[i] = i + 1 + localsize * my_id;
}
mpiio_writer(my_id, localvector, localsize);
free(localvector);
MPI_Finalize();
return 0;
}
void mpiio_writer(int my_id, int *localvector, int localsize)
{
MPI_File fh;
MPI_Offset offset;
/* TODO: Write the data to an output file "output.dat" using MPI IO. Each
process should write their own local vectors to correct location
of the output file. */
}