* example of parallel MPI write into a single file */
#include "mpi.h"
#include <stdio.h>
#define BUFSIZE 100
int main(int argc, char *argv[])
{
/* int j = 0;
char hostname[256];
gethostname(hostname, sizeof(hostname));
printf("PID %d on %s ready for attach\n", getpid(), hostname);
fflush(stdout);
while (0 == j)
sleep(5);
*/
int ret, resultlen;
int i, myrank, buf[BUFSIZE];
char msg[MPI_MAX_ERROR_STRING];
MPI_File thefile;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
for (i=0; i<BUFSIZE; i++)
buf[i] = myrank * BUFSIZE + i;
ret = MPI_File_open(MPI_COMM_WORLD, "pvfs2:/mnt/pvfs2/mpio/testfile",
MPI_MODE_CREATE | MPI_MODE_WRONLY,
MPI_INFO_NULL, &thefile);
if (ret != MPI_SUCCESS)
{
MPI_Error_string(ret, msg, &resultlen);
fprintf(stderr, "MPI_File_open(): %s\n", msg);
return(-1);
} else {
MPI_File_set_view(thefile, myrank * BUFSIZE * sizeof(int),
MPI_INT, MPI_INT, "native", MPI_INFO_NULL);
MPI_File_write(thefile, buf, BUFSIZE, MPI_INT,
MPI_STATUS_IGNORE);
MPI_File_close(&thefile);
MPI_Finalize();
return 0;
}
}
/* Flags de Compilacion de OpenMPI-1.8.1:
./configure --prefix=/home/wilderman/openmpi --with-pvfs2=/usr/local --with-pvfs2-libs=/usr/local
OrangeFS-2.8.8 (PVFS 1.8.2)
CFLAGS="-fPIC" ./configure
Comments