00001
00002
00003 #ifndef _included_CommServer_h
00004 #define _included_CommServer_h
00005
00013
00014
00015 #include "DAGHDefaults.h"
00016
00017 #include <iosfwd>
00018 #include <cassert>
00019
00020 #ifdef DAGH_NO_MPI
00021
00022 typedef unsigned MPI_Request;
00023 typedef unsigned MPI_Group;
00024 typedef unsigned MPI_Comm;
00025
00026 typedef struct {
00027 int count;
00028 int MPI_SOURCE;
00029 int MPI_TAG;
00030 } MPI_Status;
00031
00032 #define MPI_PROC_NULL (-1)
00033 #define MPI_ANY_SOURCE (-2)
00034 #define MPI_ANY_TAG (-1)
00035 #define MPI_SUCCESS (0)
00036 #define MPI_ERR_COMM (28)
00037 #define MPI_COMM_WORLD (301053)
00038
00039 inline static void MPI_Finalize() {}
00040 #else
00041
00042 #include <mpi.h>
00043
00044 #endif
00045
00046
00047
00048
00049 #define comm_service_comp ((unsigned) 0)
00050 #define comm_service_io ((unsigned) 1)
00051 #define comm_service_world ((unsigned) 2)
00052
00053 #define comm_service_tag (((unsigned) 3)<<14)
00054 #define comm_service_comp_tag ((comm_service_comp)<<12)
00055 #define comm_service_io_tag ((comm_service_io)<<12)
00056 #define comm_service_world_tag ((comm_service_world)<<12)
00057
00058 #define comm_service_null_id (-1)
00059
00060 class comm_service {
00061 private:
00062
00063
00064 static int init_flag ;
00065 static int dce_flag ;
00066
00067 static int PMe ;
00068
00069 static int NList ;
00070 static MPI_Request * RList ;
00071 static comm_service ** SList ;
00072
00073 static std::ostream* olog ;
00074
00075
00076 static int PNum ;
00077 static MPI_Comm Comm ;
00078 static MPI_Group Grp ;
00079
00080
00081 static int io_flag ;
00082 static int PIO ;
00083 static MPI_Comm CommIO ;
00084
00085
00086 static MPI_Comm CommWorld ;
00087 static int PWorld ;
00088 static MPI_Group GrpWorld ;
00089
00090
00091 static int NumCommArray ;
00092 static MPI_Comm * CommArray ;
00093
00094
00095 static double Idle_Time ;
00096 static double Srvc_Time ;
00097
00098 MPI_Request * Req ;
00099
00100 static int findTag( const int , const int , const int );
00101 static int findService( comm_service * const );
00102 static int findRequest( const MPI_Request );
00103
00104 protected:
00105
00106 const int Id ;
00107 const int Tag ;
00108 const int Src ;
00109
00110 comm_service( const int I , const int T , const int S=MPI_ANY_SOURCE );
00111 comm_service();
00112
00113 virtual ~comm_service();
00114
00115 virtual void callrecv( const MPI_Status & );
00116 virtual const char * name( void ) const ;
00117
00118 void setreq(const int, const int, const int);
00119
00120 public:
00121
00122
00123
00124 static int init( MPI_Comm c = 0 );
00125 static void clean();
00126 static void kill();
00127
00128
00129
00130 static int serve( MPI_Request );
00131 static int serve( bool nonblocking=true );
00132
00133
00134
00135 MPI_Request * req(void) const { return Req ; }
00136 int tag(void) const { return Tag ; }
00137
00138 static std::ofstream & flog(void);
00139 static std::ostream & log(void) { return *olog ; }
00140 static int dce(void) { return dce_flag ; }
00141 static int proc_me(void) { return PMe ; }
00142
00143 static int proc_num(void) { return PNum ; }
00144 static MPI_Comm comm(void) { return Comm ; }
00145 static MPI_Group grp(void) { return Grp ; }
00146
00147 static int num_services(void) { return NList ;}
00148
00149 static int comminit(void) { return (init_flag == 1); }
00150 static void set_comminit(void) { init_flag = 1; }
00151 static void reset_comminit(void) { init_flag = 0; }
00152
00153 static int io_enabled(void) { return (io_flag == 1); }
00154 static void set_io_enable(void) { io_flag = 1; }
00155 static void reset_io_enable(void) { io_flag = 0; }
00156 static int proc_io(void) { return PIO ; }
00157 static MPI_Comm comm_io(void) { return CommIO ; }
00158
00159 static MPI_Comm comm_world(void) { return CommWorld ; }
00160 static int proc_world(void) { return PWorld; }
00161 static MPI_Group grp_world(void) { return GrpWorld ; }
00162
00163 static MPI_Comm comm(int const id) { return CommArray[id] ; }
00164 static int num_comm(void) { return NumCommArray ; }
00165
00166 static void add_comm(int const id);
00167 static void delete_comm(int const id);
00168 static void reset_comm(int const id);
00169
00170 static void inc_commarray(int const inc);
00171
00172 static double idle_time(void) { return Idle_Time ; }
00173 static double srvc_time(void) { return Srvc_Time ; }
00174
00175
00176 static void error_msg( const char who[] , const char what[] , int R );
00177 static void error_die( const char who[] , const char what[] , int R );
00178 };
00179
00180 #endif