| 1 | // | 
|---|
| 2 | // messmpi.h | 
|---|
| 3 | // | 
|---|
| 4 | // Copyright (C) 1996 Limit Point Systems, Inc. | 
|---|
| 5 | // | 
|---|
| 6 | // Author: Curtis Janssen <cljanss@limitpt.com> | 
|---|
| 7 | // Maintainer: LPS | 
|---|
| 8 | // | 
|---|
| 9 | // This file is part of the SC Toolkit. | 
|---|
| 10 | // | 
|---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify | 
|---|
| 12 | // it under the terms of the GNU Library General Public License as published by | 
|---|
| 13 | // the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 14 | // any later version. | 
|---|
| 15 | // | 
|---|
| 16 | // The SC Toolkit is distributed in the hope that it will be useful, | 
|---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 19 | // GNU Library General Public License for more details. | 
|---|
| 20 | // | 
|---|
| 21 | // You should have received a copy of the GNU Library General Public License | 
|---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to | 
|---|
| 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 
|---|
| 24 | // | 
|---|
| 25 | // The U.S. Government is granted a limited license as per AL 91-7. | 
|---|
| 26 | // | 
|---|
| 27 |  | 
|---|
| 28 | #ifndef _util_group_messmpi_h | 
|---|
| 29 | #define _util_group_messmpi_h | 
|---|
| 30 |  | 
|---|
| 31 | #include <util/group/message.h> | 
|---|
| 32 | #include <util/group/thread.h> | 
|---|
| 33 |  | 
|---|
| 34 | #define MPICH_SKIP_MPICXX | 
|---|
| 35 | #include <mpi.h> | 
|---|
| 36 |  | 
|---|
| 37 | namespace sc { | 
|---|
| 38 |  | 
|---|
| 39 | /** The MPIMessageGrp class is an concrete implementation of MessageGrp | 
|---|
| 40 | that uses the MPI 1 library.  */ | 
|---|
| 41 | class MPIMessageGrp: public MessageGrp { | 
|---|
| 42 | protected: | 
|---|
| 43 | void* buf; | 
|---|
| 44 | int bufsize; | 
|---|
| 45 |  | 
|---|
| 46 | int rnode; | 
|---|
| 47 | int rtag; | 
|---|
| 48 | int rlen; | 
|---|
| 49 |  | 
|---|
| 50 | /// If true use the generic collective routines in the base class | 
|---|
| 51 | bool use_messagegrp_collectives_; | 
|---|
| 52 |  | 
|---|
| 53 | /// Number of MPIMessageGrp's currently in use. | 
|---|
| 54 | static int nmpi_grps; | 
|---|
| 55 | /// lock to access nmpi_grps variable | 
|---|
| 56 | static Ref<ThreadLock> grplock; | 
|---|
| 57 |  | 
|---|
| 58 | Ref<ThreadGrp> threadgrp; | 
|---|
| 59 | /// Currently each commgrp is a dup of MPI_COMM_WORLD | 
|---|
| 60 | MPI_Comm commgrp; | 
|---|
| 61 |  | 
|---|
| 62 | /// Not thread-safe due to race condition on nmpi_grps variable. | 
|---|
| 63 | void init(MPI_Comm comm, int *argc=0, char ***argv=0); | 
|---|
| 64 | public: | 
|---|
| 65 | MPIMessageGrp(); | 
|---|
| 66 | /** Use an MPI communicator to create a MessageGrp.  The comm | 
|---|
| 67 | argument could be a subset of MPI_COMM_WORLD, for example. */ | 
|---|
| 68 | MPIMessageGrp(MPI_Comm comm); | 
|---|
| 69 | /** Use argc and argv to create a MPIMessageGrp.  This would | 
|---|
| 70 | have to be used for implementations of MPI that have MPI_Init | 
|---|
| 71 | fill in argc and argv. */ | 
|---|
| 72 | MPIMessageGrp(int *argc, char ***argv); | 
|---|
| 73 | /** Construction MPIMessageGrp given a KeyVal input object. */ | 
|---|
| 74 | MPIMessageGrp(const Ref<KeyVal>&); | 
|---|
| 75 | ~MPIMessageGrp(); | 
|---|
| 76 |  | 
|---|
| 77 | /// Clones (dups) an MPIMessageGrp from MPI_COMM_WORLD | 
|---|
| 78 | Ref<MessageGrp> clone(void); | 
|---|
| 79 |  | 
|---|
| 80 | void raw_send(int target, const void* data, int nbyte); | 
|---|
| 81 | void raw_recv(int sender, void* data, int nbyte); | 
|---|
| 82 | void raw_sendt(int target, int type, const void* data, int nbyte); | 
|---|
| 83 | void raw_recvt(int type, void* data, int nbyte); | 
|---|
| 84 |  | 
|---|
| 85 | int probet(int type); | 
|---|
| 86 |  | 
|---|
| 87 | void sync(); | 
|---|
| 88 |  | 
|---|
| 89 | void sum(double*, int n, double*scratch = 0, int target = -1); | 
|---|
| 90 | void sum(int*, int n, int*scratch = 0, int target = -1); | 
|---|
| 91 |  | 
|---|
| 92 | void reduce(double*, int n, GrpReduce<double>&, | 
|---|
| 93 | double*scratch = 0, int target = -1); | 
|---|
| 94 | void reduce(unsigned int*, int n, GrpReduce<unsigned int>&, | 
|---|
| 95 | unsigned int*scratch = 0, int target = -1); | 
|---|
| 96 | void reduce(int*, int n, GrpReduce<int>&, | 
|---|
| 97 | int*scratch = 0, int target = -1); | 
|---|
| 98 | void reduce(char*, int n, GrpReduce<char>&, | 
|---|
| 99 | char*scratch = 0, int target = -1); | 
|---|
| 100 | void reduce(unsigned char*, int n, GrpReduce<unsigned char>&, | 
|---|
| 101 | unsigned char*scratch = 0, int target = -1); | 
|---|
| 102 | void reduce(signed char*, int n, GrpReduce<signed char>&, | 
|---|
| 103 | signed char*scratch = 0, int target = -1); | 
|---|
| 104 | void reduce(short*, int n, GrpReduce<short>&, | 
|---|
| 105 | short*scratch = 0, int target = -1); | 
|---|
| 106 | void reduce(float*, int n, GrpReduce<float>&, | 
|---|
| 107 | float*scratch = 0, int target = -1); | 
|---|
| 108 | void reduce(long*, int n, GrpReduce<long>&, | 
|---|
| 109 | long*scratch = 0, int target = -1); | 
|---|
| 110 |  | 
|---|
| 111 | void raw_bcast(void* data, int nbyte, int from); | 
|---|
| 112 | }; | 
|---|
| 113 |  | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 | #endif | 
|---|
| 117 |  | 
|---|
| 118 | // Local Variables: | 
|---|
| 119 | // mode: c++ | 
|---|
| 120 | // c-file-style: "CLJ" | 
|---|
| 121 | // End: | 
|---|