MPIGlue.h

Go to the documentation of this file.
00001 /* -*- mode: c++ -*- */
00002 //# MPIGlue.h: Smooth out source code differences for MPI vs non-MPI builds
00003 //# Copyright (C) 2016
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //
00028 // This header file is intended to facilitate writing source modules that use
00029 // MPI, so that they can also be compiled without an MPI compiler and run
00030 // without the MPI libraries. Note, however, that the definitions in this header
00031 // file do not provide a complete replacement of MPI functions with stub
00032 // versions; that task is beyond the scope of a single header file (duplicating
00033 // MPI datatypes, for example, would take much more effort). Instead, this file
00034 // is currently only used by new tclean2 code that uses MPI functions in C++,
00035 // and, therefore, only provides support for those parts of MPI that are
00036 // currently needed in the tclean2 code.
00037 #ifndef MPI_GLUE_H_
00038 #define MPI_GLUE_H_
00039 
00040 #if HAVE_MPI
00041 
00042 # include <mpi.h>
00043 # define UNUSED_WITHOUT_MPI
00044 # define MPI_BOOL_TYPE unsigned char // TODO: replace with bool under MPI-3
00045 # define MPI_BOOL MPI_UNSIGNED_CHAR // TODO: replace with MPI_CXX_BOOL under MPI-3
00046 # warning "Implementing unsafe MPI-2 workaround for MPI_Comm_group_create"
00047 # define MPI_Comm_group_create(c, g, t, pc) MPI_Comm_create(c, g, pc)
00048 
00049 #else // ! HAVE_MPI
00050 
00051 # include <cstddef>
00052 # define UNUSED_WITHOUT_MPI __attribute__((unused))
00053 # define MPI_BOOL_TYPE unsigned char
00054 # define MPI_BOOL 0
00055 # define MPI_INT 1
00056 # define MPI_FLOAT 2
00057 # define MPI_DOUBLE 3
00058 namespace casa {
00059 typedef int MPI_Comm;
00060 typedef int MPI_Group;
00061 typedef int MPI_Datatype;
00062 typedef int MPI_Op;
00063 typedef std::ptrdiff_t MPI_Aint;
00064 };
00065 # define MPI_COMM_WORLD 0
00066 # define MPI_COMM_SELF 0
00067 # define MPI_COMM_NULL -1
00068 # define MPI_GROUP_NULL -1
00069 # define MPI_UNDEFINED -1
00070 # define MPI_IN_PLACE nullptr
00071 # define MPI_Comm_size(c, sp)                       \
00072         do {                                            \
00073                 *(sp) = (((c) != MPI_COMM_NULL) ? 1 : 0);   \
00074         } while (0)
00075 # define MPI_Comm_rank(c, rp)                       \
00076         do {                                            \
00077                 *(rp) = (((c) != MPI_COMM_NULL) ? 0 : -1);  \
00078         } while (0)
00079 # define MPI_Comm_dup(c, cp)                    \
00080         do {                                        \
00081                 *(cp) = (c);                            \
00082         } while (0)
00083 # define MPI_Comm_free(c) do {} while (0)
00084 # define MPI_Comm_split(comm, color, key, cp)   \
00085         do {                                        \
00086                 *(cp) = (((color) != MPI_UNDEFINED)     \
00087                          ? (comm)                       \
00088                          : MPI_COMM_NULL);              \
00089         } while (0)
00090 # define MPI_Comm_group(c, pg) do {             \
00091                 *(pg) = (((c) != MPI_COMM_NULL)         \
00092                          ? (MPI_GROUP_NULL + 1)         \
00093                          : MPI_GROUP_NULL);             \
00094         } while (0)
00095 # define MPI_Group_free(pg) do {} while (0)
00096 # define MPI_Group_incl(g, nr, pr, pg) do {     \
00097                 if ((g) != MPI_GROUP_NULL && (nr) > 0)  \
00098                         *(pg) = MPI_GROUP_NULL + 1;         \
00099                 else                                    \
00100                         *(pg) = MPI_GROUP_NULL;             \
00101         } while (0)
00102 # define MPI_Comm_group_create(c, g, t, pc) do {            \
00103                 if ((c) != MPI_COMM_NULL && (g) != MPI_GROUP_NULL)  \
00104                         *(pc) = (c);                                    \
00105                 else                                                \
00106                         *(pc) = MPI_COMM_NULL;                          \
00107         } while (0)
00108 # define MPI_Type_create_struct(a, b, c, d, pd) do { *(pd) = 0; } while (0)
00109 # define MPI_Type_create_resized(a, b, c, pd) do { *(pd) = 0; } while (0)
00110 # define MPI_Type_free(pd) do {} while (0)
00111 # define MPI_Type_commit(pd) do {} while (0)
00112 # define MPI_Op_create(a, b, po) do { *(po) = 0; } while (0)
00113 # define MPI_Op_free(po) do {} while (0)
00114 # define MPI_Barrier(c) do {} while (0)
00115 # define MPI_Bcast(a, b, c, d, e) do {} while (0)
00116 # define MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, comm) \
00117         do {                                                            \
00118                 assert((sendbuf) == MPI_IN_PLACE);                          \
00119         } while (0)
00120 # define MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) \
00121         do {                                                                \
00122                 assert((sendbuf) == MPI_IN_PLACE                                \
00123                        && (sendtype) == (recvtype)                              \
00124                        && (sendcount) == (recvcount));                          \
00125         } while (0)
00126 # define MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm) \
00127         do {                                                                \
00128                 assert((sendbuf) == MPI_IN_PLACE                                \
00129                        && (sendtype) == (recvtype)                              \
00130                        && (sendcount) == (recvcounts)[0]);                      \
00131         } while (0)
00132 #endif // HAVE_MPI
00133 
00134 #endif // MPI_GLUE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1