Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77643886
io6.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Aug 15, 16:01
Size
1 KB
Mime Type
text/x-c
Expires
Sat, Aug 17, 16:01 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
19902297
Attached To
rPNBODY pNbody
io6.c
View Options
/* parallel MPI read with arbitrary number of processes*/
#include "mpi.h"
#include <malloc.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int myrank, numprocs, bufsize, *buf, count;
MPI_File thefile;
MPI_Status status;
MPI_Offset filesize;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_File_open(MPI_COMM_WORLD, "testfile", MPI_MODE_RDONLY,
MPI_INFO_NULL, &thefile);
MPI_File_get_size(thefile, &filesize); /* in bytes */
filesize = filesize / sizeof(int); /* in number of ints */
bufsize = filesize / numprocs + 1; /* local number to read */
buf = (int *) malloc (bufsize * sizeof(int));
MPI_File_set_view(thefile, myrank * bufsize * sizeof(int),
MPI_INT, MPI_INT, "native", MPI_INFO_NULL);
MPI_File_read(thefile, buf, bufsize, MPI_INT, &status);
MPI_Get_count(&status, MPI_INT, &count);
printf("process %d read %d ints\n", myrank, count);
MPI_File_close(&thefile);
MPI_Finalize();
return 0;
}
Event Timeline
Log In to Comment