#include "mpi.h" #include int main(int argc, char **argv) { MPI_File fh; MPI_Status status; MPI_Offset offset; int length, nprocs, rank, i; char buffer[1024]; for(i=0; i<1024; i++) buffer[i] = i; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* e.g. P0 ( off_0 = 0, len_0 > 2 ) P1 ( off_1 < len_0 - 1, len_1 = 0 ) P2 ( off_2 < len_0 - 1, len_2 = 0 ) P3 ( off_3 < len_0 - 1, len_3 = 0 ) ....... ........ */ if (rank == 0) length=nprocs; else length=0; offset = rank; MPI_File_open(MPI_COMM_WORLD, argv[1], MPI_MODE_CREATE|MPI_MODE_RDWR, MPI_INFO_NULL, &fh); MPI_File_write_at_all(fh, offset, buffer, length, MPI_BYTE, &status); MPI_File_close(&fh); MPI_Finalize(); return 0; }