Parallel.hpp

00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 #ifndef stk_util_parallel_Parallel_hpp
00010 #define stk_util_parallel_Parallel_hpp
00011 
00012 // stk_config.h resides in the build directory and contains the
00013 // complete set of #define macros for build-dependent features.
00014 
00015 #include <stk_util/stk_config.h>
00016 
00017 //----------------------------------------------------------------------
00018 // Parallel machine
00019 
00020 #if defined( STK_HAS_MPI )
00021 
00022 #include <mpi.h>
00023 
00024 namespace stk {
00025 
00030 
00031 
00032 typedef MPI_Comm     ParallelMachine ;
00033 
00035 
00036 typedef MPI_Datatype ParallelDatatype ;
00037 
00043 inline ParallelMachine parallel_machine_null() { return MPI_COMM_NULL ; }
00044 
00054 inline ParallelMachine parallel_machine_init( int * argc , char *** argv )
00055 {
00056   MPI_Init( argc , argv );
00057   return MPI_COMM_WORLD ;
00058 }
00059 
00064 inline void parallel_machine_finalize()
00065 {
00066   MPI_Finalize();
00067 }
00068 
00071 }
00072 
00073 //----------------------------------------
00074 // Other parallel communication machines go here
00075 // as '#elif defined( STK_HAS_<name> )'
00076 
00077 //----------------------------------------
00078 // Stub for non-parallel
00079 
00080 #else
00081 
00082 // Some needed stubs
00083 #define MPI_Comm int
00084 #define MPI_COMM_WORLD 0
00085 #define MPI_Barrier( a ) (void)a
00086 
00087 namespace stk {
00088 
00089 typedef int ParallelMachine ;
00090 typedef int ParallelDatatype ;
00091 
00092 inline ParallelMachine parallel_machine_null() { return 0 ; }
00093 
00094 inline ParallelMachine parallel_machine_init( int * , char *** )
00095 { return 0 ; }
00096 
00097 inline void parallel_machine_finalize()
00098 {}
00099 
00100 }
00101 
00102 #endif
00103 
00104 //----------------------------------------------------------------------
00105 // Common parallel machine needs.
00106 
00107 namespace stk {
00108 
00116 unsigned parallel_machine_size( ParallelMachine parallel_machine );
00117 
00125 unsigned parallel_machine_rank( ParallelMachine parallel_machine );
00126 
00131 void parallel_machine_barrier( ParallelMachine parallel_machine);
00132 }
00133 
00134 //----------------------------------------------------------------------
00135 
00136 #endif
00137 

Generated on Tue Jul 13 09:27:32 2010 for Sierra Toolkit by  doxygen 1.4.7