Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members

mpi.h

00001 /* -*- c++ -*- */
00002 /*
00003  * Expresso, a C++ Array template class library
00004  * Copyright (C) 1998,2004 Oskar Enoksson (enok@lysator.liu.se)
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the
00018  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA  02111-1307, USA.
00020  */
00021 #ifndef EXPRESSO_MPI_HDR
00022 #define EXPRESSO_MPI_HDR
00023 
00024 #ifdef USE_MPIPP
00025 #include <mpi++.h>
00026 #endif
00027 #ifdef USE_MPI
00028 #include <mpi.h>
00029 #endif
00030 
00031 
00032 namespace esso {
00033 
00035 
00036 #ifdef USE_MPIPP
00037 
00038   template<class T>
00039   struct MPIPPType;
00040 
00041   template<>
00042   struct MPIPPType<char> { 
00043     inline static const MPI::Datatype & Get() { return MPI::CHAR; } };
00044   template<>
00045   struct MPIPPType<unsigned char> { 
00046     inline static const MPI::Datatype & Get() { return MPI::UNSIGNED_CHAR; } };
00047   template<>
00048   struct MPIPPType<short> { 
00049     inline static const MPI::Datatype & Get() { return MPI::SHORT; } };
00050   template<>
00051   struct MPIPPType<unsigned short> { 
00052     inline static const MPI::Datatype & Get() { return MPI::UNSIGNED_SHORT; } };
00053   template<>
00054   struct MPIPPType<int> { 
00055     inline static const MPI::Datatype & Get() { return MPI::INT; } };
00056   template<>
00057   struct MPIPPType<unsigned> { 
00058     inline static const MPI::Datatype & Get() { return MPI::UNSIGNED; } };
00059   template<>
00060   struct MPIPPType<long> { 
00061     inline static const MPI::Datatype & Get() { return MPI::LONG; } };
00062   template<>
00063   struct MPIPPType<unsigned long> { 
00064     inline static const MPI::Datatype & Get() { return MPI::UNSIGNED_LONG; } };
00065   template<>
00066   struct MPIPPType<float> { 
00067     inline static const MPI::Datatype & Get() { return MPI::FLOAT; } };
00068   template<>
00069   struct MPIPPType<double> { 
00070     inline static const MPI::Datatype & Get() { return MPI::DOUBLE; } };
00071 
00074   template<int N, class Type>
00075   inline MPI::Datatype
00076   CreateMPIPPArray(const Array<N,Type> &array){
00077     if(array.IsNull())
00078       return MPI::Datatype();
00079     typedef typename Array<N,Type>::T T;
00080     MPI::Datatype type = MPIPPType<T>::Get();
00081 
00082     for(int n=0; n<N; n++) {
00083       MPI::Datatype oldtype=type;
00084       type = oldtype.Create_hvector(array.Len(n),1,
00085                                     array.Stride(n)*sizeof(T));
00086       if(n>0)
00087         oldtype.Free();
00088     }
00089     return type;
00090   }
00091 #endif
00092 #ifdef USE_MPI
00093 
00094   template<class T>
00095   struct MPIType;
00096 
00097   template<>
00098   struct MPIType<char> { 
00099     inline static MPI_Datatype Get() { return MPI_CHAR; } };
00100   template<>
00101   struct MPIType<unsigned char> { 
00102     inline static MPI_Datatype Get() { return MPI_UNSIGNED_CHAR; } };
00103   template<>
00104   struct MPIType<short> { 
00105     inline static MPI_Datatype Get() { return MPI_SHORT; } };
00106   template<>
00107   struct MPIType<unsigned short> { 
00108     inline static MPI_Datatype Get() { return MPI_UNSIGNED_SHORT; } };
00109   template<>
00110   struct MPIType<int> { 
00111     inline static MPI_Datatype Get() { return MPI_INT; } };
00112   template<>
00113   struct MPIType<unsigned> { 
00114     inline static MPI_Datatype Get() { return MPI_UNSIGNED; } };
00115   template<>
00116   struct MPIType<long> { 
00117     inline static MPI_Datatype Get() { return MPI_LONG; } };
00118   template<>
00119   struct MPIType<unsigned long> { 
00120     inline static MPI_Datatype Get() { return MPI_UNSIGNED_LONG; } };
00121   template<>
00122   struct MPIType<float> { 
00123     inline static MPI_Datatype Get() { return MPI_FLOAT; } };
00124   template<>
00125   struct MPIType<double> { 
00126     inline static MPI_Datatype Get() { return MPI_DOUBLE; } };
00127 
00130   template<int N, class Type>
00131   inline MPI_Datatype
00132   CreateMPIArray(const Array<N,Type> &array){
00133     if(array.IsNull())
00134       return MPI_DATATYPE_NULL;
00135     typedef typename Array<N,Type>::T T;
00136     MPI_Datatype type = MPIType<T>::Get();
00137 
00138     for(int n=0; n<N; n++) {
00139       MPI_Datatype oldtype = type;
00140       MPI_Type_hvector(array.Len(n), 1, array.Stride(n)*sizeof(T), 
00141                        oldtype, &type);
00142       if(n>0)
00143         MPI_Type_free(&oldtype);
00144     }
00145     return type;
00146   }
00147 #endif
00148 
00149 }
00150 
00151 #endif
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 

Generated on Thu Jun 3 00:21:25 2004 for Expresso by doxygen 1.3.3