Created
July 10, 2014 12:15
-
-
Save cwsmith/166d5beb400f3a8136f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <mpi.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main(int argc, char **argv) { | |
int rank, nprocs; | |
MPI_File file; | |
MPI_Init(&argc, &argv); | |
MPI_Comm_size(MPI_COMM_WORLD, &nprocs); | |
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
MPI_File_open(MPI_COMM_WORLD, "test.txt", MPI_MODE_CREATE|MPI_MODE_WRONLY, | |
MPI_INFO_NULL, &file); | |
char str[32]; | |
int idx[2][2] = {1,3,0,2}; | |
int val[2][2] = {10,2,1,4}; | |
for (int i=0; i< 2; i++) { | |
sprintf(str, "%-15d\n", val[rank][i]); | |
MPI_Offset offset = idx[rank][i]*16; | |
MPI_File_seek(file, offset, MPI_SEEK_SET); | |
MPI_File_get_position(file, &offset); | |
MPI_Status status; | |
printf("%d len %lu val %d offset %lld idx %d str \"%s\"\n", rank, strlen(str), val[rank][i], offset, idx[rank][i], str); | |
MPI_File_write(file, str, strlen(str), MPI_CHAR, &status); | |
} | |
MPI_File_close(&file); | |
MPI_Finalize(); | |
return 0; | |
} | |
~ |
note, this is setup for scattered indices, we will be collecting a range of contiguous indices on each part so only a single write is needed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
that should work, depending on how fast it is for all processes to seek once per element.
I vaguely remember an MPI File set size command, which might make things faster.