Parallel.hpp

00001 /*------------------------------------------------------------------------*/
00002 /*      phdMesh : Parallel Heterogneous Dynamic unstructured Mesh         */
00003 /*                Copyright (2007) Sandia Corporation                     */
00004 /*                                                                        */
00005 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00006 /*  license for use of this work by or on behalf of the U.S. Government.  */
00007 /*                                                                        */
00008 /*  This library is free software; you can redistribute it and/or modify  */
00009 /*  it under the terms of the GNU Lesser General Public License as        */
00010 /*  published by the Free Software Foundation; either version 2.1 of the  */
00011 /*  License, or (at your option) any later version.                       */
00012 /*                                                                        */
00013 /*  This library is distributed in the hope that it will be useful,       */
00014 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of        */
00015 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     */
00016 /*  Lesser General Public License for more details.                       */
00017 /*                                                                        */
00018 /*  You should have received a copy of the GNU Lesser General Public      */
00019 /*  License along with this library; if not, write to the Free Software   */
00020 /*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307   */
00021 /*  USA                                                                   */
00022 /*------------------------------------------------------------------------*/
00027 #ifndef util_Parallel_hpp
00028 #define util_Parallel_hpp
00029 
00030 // phdmesh_config.h resides in the build directory and contains the
00031 // complete set of #define macros for build-dependent features.
00032 
00033 #include <phdmesh_config.h>
00034 
00035 //----------------------------------------------------------------------
00036 // Parallel machine
00037 
00038 #if defined( HAVE_MPI )
00039 
00040 #include <mpi.h>
00041 
00042 namespace phdmesh {
00043 typedef MPI_Comm     ParallelMachine ;
00044 typedef MPI_Datatype ParallelDatatype ;
00045 
00046 inline ParallelMachine parallel_machine_null() { return MPI_COMM_NULL ; }
00047 
00048 inline ParallelMachine parallel_machine_init( int * argc , char *** argv )
00049 {
00050   MPI_Init( argc , argv );
00051   return MPI_COMM_WORLD ;
00052 }
00053 
00054 inline void parallel_machine_finalize()
00055 {
00056   MPI_Finalize();
00057 }
00058 
00059 }
00060 
00061 //----------------------------------------
00062 // Other parallel communication machines go here
00063 // as '#elif defined( PHDMESH_HAS_<name> )'
00064 
00065 //----------------------------------------
00066 // Stub for non-parallel
00067 
00068 #else
00069 
00070 namespace phdmesh {
00071 typedef int ParallelMachine ;
00072 typedef int ParallelDatatype ;
00073 
00074 inline ParallelMachine parallel_machine_null() { return 0 ; }
00075 
00076 inline ParallelMachine parallel_machine_init( int * , char *** )
00077 { return 0 ; }
00078 
00079 inline void parallel_machine_finalize()
00080 {}
00081 
00082 }
00083 
00084 #endif
00085 
00086 //----------------------------------------------------------------------
00087 // Common parallel machine needs.
00088 
00089 namespace phdmesh {
00090 
00091 double wall_time();
00092 double wall_dtime( double & );
00093 
00094 unsigned parallel_machine_size( ParallelMachine m );
00095 
00096 unsigned parallel_machine_rank( ParallelMachine m );
00097 
00098 void parallel_machine_barrier( ParallelMachine );
00099 
00102 struct IdentProc {
00103   unsigned ident ;
00104   unsigned proc ;
00105 
00106   ~IdentProc() {}
00107 
00108   IdentProc() {}
00109 
00110   IdentProc( const IdentProc & rhs ) : ident(rhs.ident), proc(rhs.proc) {}
00111 
00112   IdentProc( unsigned i , unsigned p ) : ident(i), proc(p) {}
00113 
00114   IdentProc & operator = ( const IdentProc & rhs )
00115     { ident = rhs.ident ; proc = rhs.proc ; return *this ; }
00116 
00117   bool operator == ( const IdentProc & rhs ) const
00118     { return ident == rhs.ident && proc == rhs.proc ; }
00119 
00120   bool operator != ( const IdentProc & rhs ) const
00121     { return ident != rhs.ident || proc != rhs.proc ; }
00122 
00123   bool operator < ( const IdentProc & rhs ) const
00124     { return ident != rhs.ident ? ident < rhs.ident : proc < rhs.proc ; }
00125 
00126   bool operator > ( const IdentProc & rhs ) const
00127     { return rhs.operator<( *this ); }
00128 
00129   bool operator <= ( const IdentProc & rhs ) const
00130     { return ! rhs.operator<( *this ); }
00131 
00132   bool operator >= ( const IdentProc & rhs ) const
00133     { return ! this->operator<( rhs ); }
00134 };
00135 
00136 }
00137 
00138 //----------------------------------------------------------------------
00139 
00140 #endif
00141 

Generated on Wed May 12 21:24:30 2010 for phdMesh by  doxygen 1.4.7