/* * $RCSfile: pi_mpi.idl,v $ $Revision: 1.4 $ $Date: 2005/02/16 06:01:33 $ * $AIST_Release: 4.2.4 $ * $AIST_Copyright: * Copyright 2003, 2004, 2005, 2006 Grid Technology Research Center, * National Institute of Advanced Industrial Science and Technology * Copyright 2003, 2004, 2005, 2006 National Institute of Informatics * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * $ */ Module pi_mpi; Compiler "/path/to/mpicc"; Linker "/path/to/mpicc"; Define pi_trial(IN long counter, OUT long *answer) Required "pi_trial.o" Backend "MPI" { /* Prototype declaration */ extern long pi_trial(int, long); int my_rank; int tag = 0; long times; long result; MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); if (my_rank != 0) { int dest = 0; MPI_Bcast(×, 1, MPI_LONG, 0, MPI_COMM_WORLD); result = pi_trial(my_rank, times); MPI_Send(&result, 1, MPI_LONG, dest, tag, MPI_COMM_WORLD); } else { int process_num; int source; long total; MPI_Status recv_status; MPI_Comm_size(MPI_COMM_WORLD, &process_num); times = counter / process_num; MPI_Bcast(×, 1, MPI_LONG, 0, MPI_COMM_WORLD); times += counter % process_num; total = pi_trial(my_rank, times); for (source = 1; source < process_num; source++) { MPI_Recv(&result, 1, MPI_LONG, source, tag, MPI_COMM_WORLD, &recv_status); total += result; } *answer = total; } }