Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 #ifndef _included_CommServer_h 00002 #define _included_CommServer_h 00003 00011 #include <iostream.h> 00012 #include <strstream.h> 00013 #include <fstream.h> 00014 #include "streams_CompConf.h" 00015 #include <iomanip.h> 00016 #include <assert.h> 00017 00018 /* This file contains default vaules that can overide 00019 #defines in this file. This line can be removed... */ 00020 #include "DAGHDefaults.h" 00021 00022 #ifdef DAGH_NO_MPI 00023 00024 typedef unsigned MPI_Request; 00025 typedef unsigned MPI_Group; 00026 typedef unsigned MPI_Comm; 00027 00028 typedef struct { 00029 int count; 00030 int MPI_SOURCE; 00031 int MPI_TAG; 00032 } MPI_Status; 00033 00034 #define MPI_PROC_NULL (-1) 00035 #define MPI_ANY_SOURCE (-2) 00036 #define MPI_ANY_TAG (-1) 00037 #define MPI_SUCCESS (0) 00038 #define MPI_ERR_COMM (28) 00039 #define MPI_COMM_WORLD (301053) 00040 00041 inline static void MPI_Finalize() {}; 00042 #else 00043 00044 extern "C" { 00045 #include <mpi.h> 00046 } 00047 00048 #endif 00049 00050 // --------------------------------------------------------------------- 00051 // --------------------------------------------------------------------- 00052 00053 #define comm_service_comp ((unsigned) 0) 00054 #define comm_service_io ((unsigned) 1) 00055 #define comm_service_world ((unsigned) 2) 00056 00057 #define comm_service_tag (((unsigned) 3)<<14) 00058 #define comm_service_comp_tag ((comm_service_comp)<<12) 00059 #define comm_service_io_tag ((comm_service_io)<<12) 00060 #define comm_service_world_tag ((comm_service_world)<<12) 00061 00062 #define comm_service_null_id (-1) 00063 00064 class comm_barrier ; 00065 00066 class comm_service { 00067 private: // ------------------------------------------------------------ 00068 // Static parameters 00069 00070 static int init_flag ; 00071 static int dce_flag ; 00072 00073 static int PMe ; 00074 00075 static int NList ; 00076 static MPI_Request * RList ; 00077 static comm_service ** SList ; 00078 static comm_barrier ** Barrier ; 00079 static comm_barrier ** BarrierWorld ; 00080 00081 static ofstream oflog ; 00082 static ostream* olog ; 00083 00084 // Compute Group 00085 static int PNum ; 00086 static MPI_Comm Comm ; 00087 static MPI_Group Grp ; 00088 00089 // I/O Server 00090 static int io_flag ; 00091 static int PIO ; 00092 static MPI_Comm CommIO ; 00093 00094 // Entire Proc Group 00095 static MPI_Comm CommWorld ; 00096 static int PWorld ; 00097 static MPI_Group GrpWorld ; 00098 00099 // Communication Array 00100 static int NumCommArray ; 00101 static MPI_Comm * CommArray ; 00102 00103 // Idle timer 00104 static double Idle_Time ; // Time 'idling' 00105 static double Srvc_Time ; // Time 'serving' 00106 00107 MPI_Request * Req ; 00108 00109 static int findTag( const int , const int , const int ); // By tag 00110 static int findService( comm_service * const ); // By comm_service 00111 static int findRequest( const MPI_Request ); // By request 00112 00113 protected: // ---------------------------------------------------------- 00114 00115 const int Id ; 00116 const int Tag ; 00117 const int Src ; 00118 00119 comm_service( const int I , const int T , const int S=MPI_ANY_SOURCE ); 00120 00121 virtual ~comm_service(); 00122 00123 virtual void callrecv( const MPI_Status & ); // Callback for recv 00124 virtual const char * name( void ) const ; // Derived class name 00125 00126 void setreq(const int, const int, const int); 00127 00128 public: // ------------------------------------------------------------- 00129 00130 // Initialize & kill the communication server 00131 00132 static int init( MPI_Comm c = 0 ); 00133 static void clean(); 00134 static void kill(); 00135 00136 // Perform services 00137 00138 static int serve( MPI_Request ); // Serve until request is satisfied 00139 static int serve( void ); // Serve all stockpiled requests 00140 00141 static void barrier( int const type = comm_service_comp ); 00142 00143 // General info 00144 00145 MPI_Request * req(void) const { return Req ; } 00146 int tag(void) const { return Tag ; } 00147 00148 static ofstream & flog(void) { return oflog ; } 00149 static ostream & log(void) { return *olog ; } 00150 static int dce(void) { return dce_flag ; } 00151 static int proc_me(void) { return PMe ; } 00152 00153 static int proc_num(void) { return PNum ; } 00154 static MPI_Comm comm(void) { return Comm ; } 00155 static MPI_Group grp(void) { return Grp ; } 00156 00157 static int num_services(void) { return NList ;} 00158 00159 static int comminit(void) { return (init_flag == 1); } 00160 static void set_comminit(void) { init_flag = 1; } 00161 static void reset_comminit(void) { init_flag = 0; } 00162 00163 static int io_enabled(void) { return (io_flag == 1); } 00164 static void set_io_enable(void) { io_flag = 1; } 00165 static void reset_io_enable(void) { io_flag = 0; } 00166 static int proc_io(void) { return PIO ; } 00167 static MPI_Comm comm_io(void) { return CommIO ; } 00168 00169 static MPI_Comm comm_world(void) { return CommWorld ; } 00170 static int proc_world(void) { return PWorld; } 00171 static MPI_Group grp_world(void) { return GrpWorld ; } 00172 00173 static MPI_Comm comm(int const id) { return CommArray[id] ; } 00174 static int num_comm(void) { return NumCommArray ; } 00175 00176 static void add_comm(int const id); 00177 static void delete_comm(int const id); 00178 static void reset_comm(int const id); 00179 00180 static void inc_commarray(int const inc); 00181 00182 static double idle_time(void) { return Idle_Time ; } 00183 static double srvc_time(void) { return Srvc_Time ; } 00184 00185 // Error handling 00186 static void error_msg( const char who[] , const char what[] , int R ); 00187 static void error_die( const char who[] , const char what[] , int R ); 00188 }; 00189 00190 #endif
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04