Just started off with Openmpi. Trying to write and read ints to a file .. code for writing:
the characters getting written to the file are unrecognizable, mostly garbage.
#include <stdlib.h>
#include <stdio.h>
#include "mpi.h"
#define BUFSIZE 10
#define FIRSTCHAR 1
#define FILENAME "file1.dat"
int main(int argc, char* argv[]) {
int i, np, me;
int buf[BUFSIZE]; /* The buffer to write */
MPI_File myfile; /* Shared file */
/* Initialize MPI */
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &me);
MPI_Comm_size(MPI_COMM_WORLD, &np);
/* Initialize buf with characters. Process 0 uses 'a', process 1 'b', etc. */
for (i=0; i<BUFSIZE; i++) {
buf[i] = FIRSTCHAR+(me);
}
/* Open the file */
MPI_File_open (MPI_COMM_WORLD, FILENAME, MPI_MODE_CREATE | MPI_MODE_WRONLY,
MPI_INFO_NULL, &myfile);
/* Set the file view */
MPI_File_set_view(myfile, me*BUFSIZE*sizeof(int), MPI_INT, MPI_INT,
"native", MPI_INFO_NULL);
/* Write buf to the file */
MPI_File_write(myfile, buf, BUFSIZE*sizeof(int), MPI_INT, MPI_STATUS_IGNORE);
/* Close the file */
MPI_File_close(&myfile);
MPI_Finalize();
exit(0);
}
dosen't work .. Please help!