/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! !! !! GNU General Public License !! !! !! !! This file is part of the Flexible Modeling System (FMS). !! !! !! !! FMS is free software; you can redistribute it and/or modify !! !! it and are expected to follow the terms of the GNU General Public !! !! License as published by the Free Software Foundation. !! !! !! !! FMS is distributed in the hope that it will be useful, !! !! but WITHOUT ANY WARRANTY; without even the implied warranty of !! !! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the !! !! GNU General Public License for more details. !! !! !! !! You should have received a copy of the GNU General Public License !! !! along with FMS; if not, write to: !! !! Free Software Foundation, Inc. !! !! 59 Temple Place, Suite 330 !! !! Boston, MA 02111-1307 USA !! !! or see: !! !! http://www.gnu.org/licenses/gpl.txt !! !! !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ #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