casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MPIGlue.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
2 //# MPIGlue.h: casacore::Smooth out source code differences for MPI vs non-MPI builds
3 //# Copyright (C) 2016
4 //# Associated Universities, Inc. Washington DC, USA.
5 //#
6 //# This library is free software; you can redistribute it and/or modify it
7 //# under the terms of the GNU Library General Public License as published by
8 //# the Free Software Foundation; either version 2 of the License, or (at your
9 //# option) any later version.
10 //#
11 //# This library is distributed in the hope that it will be useful, but WITHOUT
12 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 //# License for more details.
15 //#
16 //# You should have received a copy of the GNU Library General Public License
17 //# along with this library; if not, write to the Free Software Foundation,
18 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19 //#
20 //# Correspondence concerning AIPS++ should be addressed as follows:
21 //# Internet email: aips2-request@nrao.edu.
22 //# Postal address: AIPS++ Project Office
23 //# National Radio Astronomy Observatory
24 //# 520 Edgemont Road
25 //# Charlottesville, VA 22903-2475 USA
26 //#
27 //
28 // This header file is intended to facilitate writing source modules that use
29 // MPI, so that they can also be compiled without an MPI compiler and run
30 // without the MPI libraries. Note, however, that the definitions in this header
31 // file do not provide a complete replacement of MPI functions with stub
32 // versions; that task is beyond the scope of a single header file (duplicating
33 // MPI datatypes, for example, would take much more effort). Instead, this file
34 // is currently only used by new tclean2 code that uses MPI functions in C++,
35 // and, therefore, only provides support for those parts of MPI that are
36 // currently needed in the tclean2 code.
37 #ifndef MPI_GLUE_H_
38 #define MPI_GLUE_H_
39 
40 #if HAVE_MPI
41 
42 # include <mpi.h>
43 # define UNUSED_WITHOUT_MPI
44 # define MPI_BOOL_TYPE unsigned char // TODO: replace with bool under MPI-3
45 # define MPI_BOOL MPI_UNSIGNED_CHAR // TODO: replace with MPI_CXX_BOOL under MPI-3
46 # warning "Implementing unsafe MPI-2 workaround for MPI_Comm_group_create"
47 # define MPI_Comm_group_create(c, g, t, pc) MPI_Comm_create(c, g, pc)
48 
49 #else // ! HAVE_MPI
50 
51 # include <cstddef>
52 # define UNUSED_WITHOUT_MPI __attribute__((unused))
53 # define MPI_BOOL_TYPE unsigned char
54 # define MPI_BOOL 0
55 # define MPI_INT 1
56 # define MPI_FLOAT 2
57 # define MPI_DOUBLE 3
58 namespace casa {
59 typedef int MPI_Comm;
60 typedef int MPI_Group;
61 typedef int MPI_Datatype;
62 typedef int MPI_Op;
63 typedef std::ptrdiff_t MPI_Aint;
64 };
65 # define MPI_COMM_WORLD 0
66 # define MPI_COMM_SELF 0
67 # define MPI_COMM_NULL -1
68 # define MPI_GROUP_NULL -1
69 # define MPI_UNDEFINED -1
70 # define MPI_IN_PLACE nullptr
71 # define MPI_Comm_size(c, sp) \
72  do { \
73  *(sp) = (((c) != MPI_COMM_NULL) ? 1 : 0); \
74  } while (0)
75 # define MPI_Comm_rank(c, rp) \
76  do { \
77  *(rp) = (((c) != MPI_COMM_NULL) ? 0 : -1); \
78  } while (0)
79 # define MPI_Comm_dup(c, cp) \
80  do { \
81  *(cp) = (c); \
82  } while (0)
83 # define MPI_Comm_free(c) do {} while (0)
84 # define MPI_Comm_split(comm, color, key, cp) \
85  do { \
86  *(cp) = (((color) != MPI_UNDEFINED) \
87  ? (comm) \
88  : MPI_COMM_NULL); \
89  } while (0)
90 # define MPI_Comm_group(c, pg) do { \
91  *(pg) = (((c) != MPI_COMM_NULL) \
92  ? (MPI_GROUP_NULL + 1) \
93  : MPI_GROUP_NULL); \
94  } while (0)
95 # define MPI_Group_free(pg) do {} while (0)
96 # define MPI_Group_incl(g, nr, pr, pg) do { \
97  if ((g) != MPI_GROUP_NULL && (nr) > 0) \
98  *(pg) = MPI_GROUP_NULL + 1; \
99  else \
100  *(pg) = MPI_GROUP_NULL; \
101  } while (0)
102 # define MPI_Comm_group_create(c, g, t, pc) do { \
103  if ((c) != MPI_COMM_NULL && (g) != MPI_GROUP_NULL) \
104  *(pc) = (c); \
105  else \
106  *(pc) = MPI_COMM_NULL; \
107  } while (0)
108 # define MPI_Type_create_struct(a, b, c, d, pd) do { *(pd) = 0; } while (0)
109 # define MPI_Type_create_resized(a, b, c, pd) do { *(pd) = 0; } while (0)
110 # define MPI_Type_free(pd) do {} while (0)
111 # define MPI_Type_commit(pd) do {} while (0)
112 # define MPI_Op_create(a, b, po) do { *(po) = 0; } while (0)
113 # define MPI_Op_free(po) do {} while (0)
114 # define MPI_Barrier(c) do {} while (0)
115 # define MPI_Bcast(a, b, c, d, e) do {} while (0)
116 # define MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, comm) \
117  do { \
118  assert((sendbuf) == MPI_IN_PLACE); \
119  } while (0)
120 # define MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) \
121  do { \
122  assert((sendbuf) == MPI_IN_PLACE \
123  && (sendtype) == (recvtype) \
124  && (sendcount) == (recvcount)); \
125  } while (0)
126 # define MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) \
127  do { \
128  assert((sendbuf) == MPI_IN_PLACE \
129  && (sendtype) == (recvtype) \
130  && (sendcount) == (recvcounts)[0]); \
131  } while (0)
132 #endif // HAVE_MPI
133 
134 #endif // MPI_GLUE_H_
int MPI_Comm
Definition: MPIGlue.h:59
std::ptrdiff_t MPI_Aint
Definition: MPIGlue.h:63
int MPI_Datatype
Definition: MPIGlue.h:61
int MPI_Op
Definition: MPIGlue.h:62
int MPI_Group
Definition: MPIGlue.h:60