/* * MPI version of pipeline. * */ #include #include #include #include /* Let's assume a picture is stored as an array of N integers */ #define num_pic 10 #define N 20 #define tag 123 /************************************************************************** * Processor 1 *************************************************************************/ void get_picture_from_somewhere(int* pic) { static int i = 0; pic[0] = i++; /* or whatever */ } void trans1(int *src, int *dst) /* transforms src to dst */ { printf("Stage 1: Processing picture %d\n", src[0]); dst[0] = src[0]; } void stage1 () { int in_pic[N], int_pic_1[N]; int i; for (i=0; i<10; i++) { get_picture_from_somewhere(in_pic); trans1(in_pic, int_pic_1); MPI_Send (int_pic_1, N, MPI_INT, 1, tag, MPI_COMM_WORLD); } } /************************************************************************** * Processor 2 *************************************************************************/ void trans2 (int *src, int *dst) { printf("Stage 2: Processing picture %d\n", src[0]); dst[0] = src[0]; } void stage2 () { MPI_Status status; int int_pic_1[N], int_pic_2[N]; int i; for (i=0; i