Page MenuHomec4science

image_parts_gather.c
No OneTemporary

File Metadata

Created
Sat, May 3, 13:29

image_parts_gather.c

#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