/** * Generated by pabble-mpi v1.2.1 * Date: Mon Oct 27 12:13:49 2014 */ #include #include #include #include #include #include /*** MPI tags ***/ #define Init 0 #define Map 1 #define Reduce 2 #define Finish 3 #define Worker_RANK(x) (0+((x)-(1))) extern meta_t meta; int main(int argc, char *argv[]) { double ts_overall=0.0, ts_protocol=0.0; MPI_Init(&argc, &argv); ts_overall = MPI_Wtime(); meta.comm = MPI_COMM_WORLD; MPI_Comm_rank(MPI_COMM_WORLD, &meta.pid); MPI_Comm_size(MPI_COMM_WORLD, &meta.nprocs); MPI_Group world_grp; MPI_Comm_group(MPI_COMM_WORLD, &world_grp); /** Declarations (Protocol MapReduce) **/ int N = ((int) pow((double)meta.nprocs, 1/1)); MPI_Barrier(MPI_COMM_WORLD); /* Protocol begin */ #pragma pabble type S typedef void S; MPI_Datatype MPI_S = MPI_BYTE; S *bufMap0_r; S *bufMap0_s; #pragma pabble type T typedef void T; MPI_Datatype MPI_T = MPI_BYTE; T *bufReduce1_r; T *bufReduce1_s; ts_protocol=MPI_Wtime(); #pragma pabble Init /* Scatter if Worker[1] Map(S) to __All; if __All Map(S) from Worker[1]; */ bufMap0_r = calloc(meta.buflen(Map), sizeof(S)); #pragma pabble Map bufMap0_s = pabble_sendq_dequeue(); MPI_Scatter(bufMap0_s, meta.buflen(Map), MPI_S, bufMap0_r, meta.buflen(Map), MPI_S, Worker_RANK(1), meta.comm); free(bufMap0_s); pabble_recvq_enqueue(Map, bufMap0_r); #pragma pabble Map /* Gather if Worker[1] Reduce(T) from __All; if __All Reduce(T) to Worker[1]; */ bufReduce1_r = calloc(meta.buflen(Reduce)*meta.nprocs, sizeof(T)); #pragma pabble Reduce bufReduce1_s = pabble_sendq_dequeue(); MPI_Gather(bufReduce1_s, meta.buflen(Reduce), MPI_T, bufReduce1_r, meta.buflen(Reduce), MPI_T, Worker_RANK(1), meta.comm); free(bufReduce1_s); pabble_recvq_enqueue(Reduce, bufReduce1_r); #pragma pabble Reduce #pragma pabble Finish MPI_Barrier(MPI_COMM_WORLD); /* Protocol end */ ts_protocol=MPI_Wtime()-ts_protocol; ts_overall=MPI_Wtime()-ts_overall; MPI_Finalize(); if (meta.pid==0) fprintf(stderr, "Protocol=%fs Overall=%f\n", ts_protocol, ts_overall); return EXIT_SUCCESS; }