ESScript  Revision_
Esys_MPI.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15 
16 
17 #ifndef INC_ESYS_MPI
18 #define INC_ESYS_MPI
19 
20 #include "system_dep.h"
21 #include "types.h"
22 
23 #include <sstream>
24 
25 #ifdef ESYS_MPI
26  #include "mpi_C.h"
27 #else
28  typedef int MPI_Comm;
29  typedef int MPI_Request;
30  #define MPI_INT 6
31  #define MPI_DOUBLE 11
32  #define MPI_COMM_WORLD 91
33 #endif
34 
35 typedef int Esys_MPI_rank;
36 
37 #define ESYS_MPI_TODO { fprintf( stdout, "\nTODO : %s:%d\n", __FILE__, __LINE__); MPI_Finalize(); exit(1); }
38 
39 // Modding by 7 digit prime to avoid overflow
40 #define ESYS_MPI_INC_COUNTER(V,I) {(V).msg_tag_counter=((V).msg_tag_counter+(I))%1010201;}
41 #define ESYS_MPI_SET_COUNTER(V,I) {(V).msg_tag_counter=(I)%1010201;}
42 
43 /* Datatypes */
44 
46 struct Esys_MPIInfo {
48  int size;
52 };
53 
54 typedef struct Esys_MPIInfo Esys_MPIInfo;
55 
56 /* Function prototypes */
57 
60 
63 
66 
68 int Esys_MPIInfo_initialized( void );
69 
72 
74 dim_t Esys_MPIInfo_setDistribution(Esys_MPIInfo* in ,index_t min_id,index_t max_id,index_t* distribution);
75 
77 void Esys_MPIInfo_Split( Esys_MPIInfo *mpi_info, dim_t n, dim_t* local_N,index_t* offset);
78 
80 bool Esys_MPIInfo_noError( Esys_MPIInfo *mpi_info);
81 
82 namespace esysUtils {
83 
86 inline std::string appendRankToFileName(const std::string &fileName,
87  int mpiSize, int mpiRank)
88 {
89  std::stringstream ss;
90  ss << fileName;
91  if (mpiSize > 1) {
92  ss << '.';
93  ss.fill('0');
94  ss.width(4);
95  ss << mpiRank;
96  }
97  std::string result(ss.str());
98  return result;
99 }
100 
101 /* has the have sub-communicators been created? */
102 bool getSplitWorld();
103 /* record that a sub-communicator has been created or used */
104 void splitWorld();
105 
106 } // namespace esysUtils
107 
108 #endif /* INC_ESYS_MPI */
109