Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F111585263
image_parts_gather.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
Sat, May 3, 13:29
Size
921 B
Mime Type
text/x-c
Expires
Mon, May 5, 13:29 (2 d)
Engine
blob
Format
Raw Data
Handle
25954529
Attached To
R7871 phys-743-exercises
image_parts_gather.c
View Options
#include <stdio.h>
#include <mpi.h>
#define image_size 1024
int main(int argc, char *argv[]) {
int myrank, mysize;
int * imgPart;
int * buf;
int i;
int partSize;
int count;
MPI_Request request;
MPI_Status status;
MPI_Status s;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Comm_size(MPI_COMM_WORLD, &mysize);
imgPart = (int*)malloc(image_size/mysize * sizeof(int));
/* Generate image parts */
for (i=0; i < (image_size/mysize) ; i++){
imgPart[i] = myrank * 1;
}
partSize = image_size/mysize;
/* Process 0 is the root of the collective, i.e. the receiver of all parts */
if (myrank == 0) /* Only the root must allocate buf */
buf = (int*)malloc(image_size* sizeof(int));
MPI_Gather(imgPart, partSize, MPI_INT, buf, partSize, MPI_INT, 0, MPI_COMM_WORLD);
free(imgPart);
if (myrank==0) free(buf);
MPI_Finalize();
}
Event Timeline
Log In to Comment