#include #include #ifdef use_libMPI #include #endif #include "mpp.h" /**************************************************** global variables *****************************************************/ int npes, root_pe, pe; int *pelist=NULL; const int tag = 1; #ifdef use_libMPI MPI_Request *request; #endif /************************************************************** void mpp_init() this routine will create communicator. ***************************************************************/ void mpp_init(int *argc, char ***argv) { int n; #ifdef use_libMPI MPI_Init(argc, argv); MPI_Comm_rank(MPI_COMM_WORLD,&pe); MPI_Comm_size(MPI_COMM_WORLD,&npes); request = (MPI_Request *)malloc(npes*sizeof(MPI_Request)); for(n=0; nto_pe in queue */ if(request[to_pe] != MPI_REQUEST_NULL) { MPI_Wait( request+to_pe, &status ); } MPI_Isend(data, size, MPI_DOUBLE, to_pe, tag, MPI_COMM_WORLD, request+to_pe); #endif }; /* mpp_send_double */ /************************************************************* void mpp_send_int(const int* data, int size, int to_pe) send data to "to_pe" *************************************************************/ void mpp_send_int(const int* data, int size, int to_pe) { #ifdef use_libMPI MPI_Status status; if(request[to_pe] != MPI_REQUEST_NULL) { MPI_Wait( request+to_pe, &status ); } MPI_Isend(data, size, MPI_INT, to_pe, tag, MPI_COMM_WORLD, request+to_pe); #endif }; /* mpp_send_int */ /*********************************************************** void mpp_recv_double(double* data, int size, int from_pe) receive data from "from_pe" ***********************************************************/ void mpp_recv_double(double* data, int size, int from_pe) { #ifdef use_libMPI MPI_Status status; MPI_Recv(data, size, MPI_DOUBLE, from_pe, MPI_ANY_TAG, MPI_COMM_WORLD,&status); #endif }; /* mpp_recv_double */ /*********************************************************** void mpp_recv_int(int* data, int size, int from_pe) receive data from "from_pe" ***********************************************************/ void mpp_recv_int(int* data, int size, int from_pe) { #ifdef use_libMPI MPI_Status status; MPI_Recv(data, size, MPI_INT, from_pe, MPI_ANY_TAG, MPI_COMM_WORLD,&status); #endif }; /* mpp_recv_int */ /******************************************************************************* int mpp_sum_int(int count, int *data) sum integer over all the pes. *******************************************************************************/ void mpp_sum_int(int count, int *data) { #ifdef use_libMPI int i; int *sum; sum = (int *)malloc(count*sizeof(int)); MPI_Allreduce(data, sum, count, MPI_INT, MPI_SUM, MPI_COMM_WORLD); for(i=0; i