Go to the documentation of this file.00001 #ifndef MPI_UTILS_H
00002 #define MPI_UTILS_H
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 #include <iostream>
00011 #include <cstdlib>
00012 #include <stdint.h>
00013 #include <mpi.h>
00014 
00015 
00016 
00017 
00018 inline MPI_Datatype mpi_typeof(char)                       {return MPI_CHAR;}
00019 inline MPI_Datatype mpi_typeof(signed short)               {return MPI_SHORT;}
00020 inline MPI_Datatype mpi_typeof(signed int)                 {return MPI_INT;}
00021 inline MPI_Datatype mpi_typeof(signed long)                {return MPI_LONG;}
00022 inline MPI_Datatype mpi_typeof(unsigned char)              {return MPI_UNSIGNED_CHAR;}
00023 inline MPI_Datatype mpi_typeof(unsigned short)             {return MPI_UNSIGNED_SHORT;}
00024 inline MPI_Datatype mpi_typeof(unsigned)                   {return MPI_UNSIGNED;}
00025 inline MPI_Datatype mpi_typeof(unsigned long)              {return MPI_UNSIGNED_LONG;}
00026 inline MPI_Datatype mpi_typeof(signed long long)           {return MPI_LONG_LONG_INT;}
00027 inline MPI_Datatype mpi_typeof(double)                     {return MPI_DOUBLE;}
00028 inline MPI_Datatype mpi_typeof(long double)                {return MPI_LONG_DOUBLE;}
00029 inline MPI_Datatype mpi_typeof(std::pair<int,int>)         {return MPI_2INT;}
00030 inline MPI_Datatype mpi_typeof(std::pair<float,int>)       {return MPI_FLOAT_INT;}
00031 inline MPI_Datatype mpi_typeof(std::pair<double,int>)      {return MPI_DOUBLE_INT;}
00032 inline MPI_Datatype mpi_typeof(std::pair<long double,int>) {return MPI_LONG_DOUBLE_INT;}
00033 inline MPI_Datatype mpi_typeof(std::pair<short,int>)       {return MPI_SHORT_INT;}
00034 
00035 
00036 
00037 
00038 
00039 #define MPI_SIZE_T      (mpi_typeof(size_t()))
00040 #define MPI_INTPTR_T    (mpi_typeof(intptr_t()))
00041 #define MPI_UINTPTR_T   (mpi_typeof(uintptr_t()))
00042 
00043 
00044 
00045 
00046 
00047 inline int mpi_packed_size(int count, MPI_Datatype type, MPI_Comm comm) {
00048   int size;
00049   MPI_Pack_size(count, type, comm, &size);
00050   return size;
00051 }
00052 
00053 
00054 
00055 
00056 inline int pmpi_packed_size(int count, MPI_Datatype type, MPI_Comm comm) {
00057   int size;
00058   PMPI_Pack_size(count, type, comm, &size);
00059   return size;
00060 }
00061 
00062 
00063 #endif // MPI_UTILS_H