diff --git a/CMakeLists.txt b/CMakeLists.txt index bb7dd7f295625efe3e200b98388f20b54635cd09..725ff01b6fd04dace2dd90472a34829c6dc9ed7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,13 +149,6 @@ if(HAVE_TIME_H AND HAVE_SYS_TIME_H) set(TIME_WITH_SYS_TIME True) endif() -# do everything in the subdirs (order matters because of library dependencies!) -if(UG_ENABLE_PARALLEL) - set(SUBDIRS parallel) -else() - set(SUBDIRS "") -endif() -set(SUBDIRS ${SUBDIRS} low dev gm dom np ui lib) set(CMAKE_INSTALL_PKGINCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/ug") # create and install pkg-config information and @@ -176,10 +169,17 @@ configure_file(ug-config-version.cmake.in ug-config-version.cmake @ONLY) #install header install(FILES initug.h DESTINATION ${CMAKE_INSTALL_PKGINCLUDEDIR}) -foreach(i ${SUBDIRS}) - add_subdirectory(${i}) -endforeach(i ${SUBDIRS}) +if(UG_ENABLE_PARALLEL) + add_subdirectory(parallel) +endif() +add_subdirectory(low) +add_subdirectory(dev) +add_subdirectory(gm) +add_subdirectory(dom) +add_subdirectory(np) +add_subdirectory(ui) +add_subdirectory(lib) add_subdirectory(cmake/modules) # set variable names for config.h set(DDD_MAX_PROCBITS_IN_GID ${UG_DDD_MACROBITS}) diff --git a/parallel/ddd/basic/io.cc b/parallel/ddd/basic/io.cc index 21bdf7c773e3f583edf573a452cf0045da09a1be..ff56482efd6ae00c02475c62183d3e7a73f85c94 100644 --- a/parallel/ddd/basic/io.cc +++ b/parallel/ddd/basic/io.cc @@ -73,7 +73,7 @@ void DDD_PrintLine (const char *s) } else { - PrintHostMessage(s); + printf("%s", s); } } diff --git a/parallel/ddd/include/ddd.h b/parallel/ddd/include/ddd.h index 04dff48d7a2c6e9b46c4f77e9a3a9a6c559e658d..b885d8ddd14161fc85c8aaa007e2a4ec2ab79777 100644 --- a/parallel/ddd/include/ddd.h +++ b/parallel/ddd/include/ddd.h @@ -313,28 +313,6 @@ typedef DDD_HEADER * DDD_HDR; #define DDD_ATTR_NULL 0 -/* types of handlers for HandlerRegister */ -/* this is supported for downward compatibility only, - will be removed in further versions. kb 970212, ddd-1.7.8 */ - -enum Handlers { - HANDLER_LDATACONSTRUCTOR = 0, - HANDLER_DESTRUCTOR, - HANDLER_DELETE, - HANDLER_UPDATE, - HANDLER_OBJMKCONS, - HANDLER_SETPRIORITY, - HANDLER_XFERCOPY, - HANDLER_XFERDELETE, - HANDLER_XFERGATHER, - HANDLER_XFERSCATTER, - HANDLER_XFERGATHERX, - HANDLER_XFERSCATTERX, - HANDLER_XFERCOPYMANIP, - HANDLER_END=999 -}; - - /* handler prototypes */ /* handlers related to certain DDD_TYPE (i.e., member functions) */ diff --git a/parallel/dddif/debugger.cc b/parallel/dddif/debugger.cc index 2bf4b5cefd89e86c6d099a1a73d7dbb3416ad5b5..f838bcaf063a290fbfbb0a1e4d20b682f82111e8 100644 --- a/parallel/dddif/debugger.cc +++ b/parallel/dddif/debugger.cc @@ -25,40 +25,6 @@ using namespace PPIF; /****************************************************************************/ -/****************************************************************************/ - -void NS_DIM_PREFIX ddd_DisplayContext (void) -{ - int i, last=-1; - char sep[2] = ""; - char buf[20]; - - /* only master should display context */ - if (me!=master) - return; - - UserWrite("current context: ("); - for(i=0; i<procs+1; i++) - { - if (i>=procs || !CONTEXT(i)) - { - if (last+1==i-1) - { - sprintf(buf, "%s%d", sep, last+1); UserWrite(buf); - sep[0] = ','; - } - if (last+1<i-1) - { - sprintf(buf, "%s%d-%d", sep, last+1, i-1); UserWrite(buf); - sep[0] = ','; - } - last = i; - } - } - UserWrite(")\n"); -} - - /****************************************************************************/ /* dddif_DisplayMemoryUsage - @@ -124,9 +90,7 @@ void NS_DIM_PREFIX ddd_pstat (char *arg) break; case 'm' : - SYNC_CONTEXT; dddif_DisplayMemoryUsage(); - SYNC_END; break; case 'c' : @@ -135,10 +99,8 @@ void NS_DIM_PREFIX ddd_pstat (char *arg) break; case 's' : - SYNC_CONTEXT; DDD_Status(); UserWrite("\n"); - SYNC_END; break; case 't' : @@ -184,22 +146,18 @@ void NS_DIM_PREFIX ddd_pstat (char *arg) { DDD_IF ifId = atoi(arg+1); - SYNC_CONTEXT; if (ifId<=0) DDD_IFDisplayAll(); else DDD_IFDisplay(ifId); UserWrite("\n"); - SYNC_END; } break; case 'l' : - SYNC_CONTEXT; DDD_ListLocalObjects(); UserWrite("\n"); - SYNC_END; break; case 'b' : @@ -683,7 +641,6 @@ void NS_DIM_PREFIX dddif_PrintGridRelations (MULTIGRID *theMG) GRID *theGrid = GRID_ON_LEVEL(theMG,TOPLEVEL(theMG)); INT j; - SYNC_CONTEXT; for(e=FIRSTELEMENT(theGrid); e!=NULL; e=SUCCE(e)) { printf(PREFIX "master(e" EGID_FMT ", p%02d).\n", EGID(e), me); @@ -697,7 +654,6 @@ void NS_DIM_PREFIX dddif_PrintGridRelations (MULTIGRID *theMG) } } } - SYNC_END; } diff --git a/parallel/dddif/initddd.cc b/parallel/dddif/initddd.cc index acea62805f56daf6c7cbf889131174225d048004..abeebf2c3efae8fb17c0a0a9234032a0d854851d 100644 --- a/parallel/dddif/initddd.cc +++ b/parallel/dddif/initddd.cc @@ -1054,15 +1054,6 @@ int NS_DIM_PREFIX InitDDD (void) /* dont delete objects when another copy comes in during Xfer */ DDD_SetOption(OPT_XFER_PRUNE_DELETE, OPT_ON); - /* initialize context */ - /* TODO: malloc() should be replaced by HEAPs or ddd_memmgr */ - dddctrl._context = (INT *)malloc(sizeof(INT)*procs); - - /* initial context is all processors */ - for(i=0; i<procs; i++) - dddctrl._context[i] = 1; - - /* initialize type mapping arrays */ for(i=0; i<MAXOBJECTS; i++) { @@ -1116,10 +1107,6 @@ int NS_DIM_PREFIX InitDDD (void) int NS_DIM_PREFIX ExitDDD (void) { - /* free memory allocated by InitParallel */ - if (dddctrl._context!=NULL) - free(dddctrl._context); - DDD_Exit(); return 0; /* no error */ diff --git a/parallel/dddif/parallel.h b/parallel/dddif/parallel.h index ddee7f46855024dc9dc97e25e0e1946425e3f8ee..5f4dccc6b4dc4957a32117c642f6501212848e87 100644 --- a/parallel/dddif/parallel.h +++ b/parallel/dddif/parallel.h @@ -85,18 +85,9 @@ enum HandlerSets #define DDD_PrioritySet(h,p) {ObjectPriorityUpdate((DDD_OBJ)h,p); DDD_PrioChange(h,p);} #endif -/* macros for processor-synchronized output */ -#define SYNC_ALL { int _p; for(_p=0; _p<procs; _p++) { \ - Synchronize(); if(_p==me) { -#define SYNC_CONTEXT { int _p; for(_p=0; _p<procs; _p++) { \ - Synchronize(); if((_p==me)&&CONTEXT(me)) { -#define SYNC_END }}} - - #define UGTYPE(t) (dddctrl.ugtypes[(t)]) #define DDDTYPE(t) (dddctrl.types[(t)]) #define HAS_DDDHDR(t) (dddctrl.dddObj[(t)]) -#define CONTEXT(p) (dddctrl._context[(p)]) #define DDD_DOMAIN_DATA DDD_USER_DATA+1 #define DDD_EXTRA_DATA DDD_USER_DATA+2 @@ -244,18 +235,12 @@ typedef struct int elemData; int sideData; - /* data for memmgr */ - MULTIGRID *memmgrMG; - INT ugtypes[MAXDDDTYPES]; /* dddtype -> ugtype */ DDD_TYPE types[MAXOBJECTS]; /* ugtype -> dddtype */ int dddObj[MAXOBJECTS]; /* status of DDDIF */ - int allTypesDefined; - - /* context information, will be allocated with size=procs */ - INT *_context; + bool allTypesDefined; } DDD_CTRL; extern DDD_CTRL dddctrl; @@ -277,7 +262,6 @@ void InitCurrMG (MULTIGRID *); /* from debugger.c */ void ddd_pstat (char *); -void ddd_DisplayContext (void); /* from lb.c */ void lbs (const char *argv, MULTIGRID *theMG); diff --git a/parallel/ppif/MPI/ppif.cc b/parallel/ppif/MPI/ppif.cc index e4baa559b595ca31b6d85641e44e0f7a2b0fbb2b..e3b809ff6b146e04af2e24514de5581267202f03 100644 --- a/parallel/ppif/MPI/ppif.cc +++ b/parallel/ppif/MPI/ppif.cc @@ -72,15 +72,10 @@ using namespace PPIF; /* */ /****************************************************************************/ -#define RAND_MSG_SIZE 128 /* max size of random messages */ #define MAXT 15 /* maximum number of downtree nodes max */ /* log2(P) */ -#define PTYPE_ANY -1L /* process type: any process */ -#define ID_ARRAY 100 /* channel id: array */ #define ID_TREE 101 /* channel id: tree */ -#define ID_GLOBAL 102 /* channel id: global */ -#define ID_MAIL 103 /* channel id: mail */ #define PPIF_SUCCESS 0 /* Return value for success */ #define PPIF_FAILURE 1 /* Return value for failure */ @@ -93,13 +88,20 @@ using namespace PPIF; /* */ /****************************************************************************/ -typedef struct { +namespace PPIF { + +struct VChannel +{ int p; int chanid; -} MPIVChannel; +}; -typedef MPIVChannel *MPIVChannelPtr; +struct Msg +{ + MPI_Request req; +}; +} /* namespace PPIF */ /****************************************************************************/ /* */ @@ -129,15 +131,6 @@ VChannelPtr PPIF::uptree = NULL; /* channel uptree VChannelPtr PPIF::downtree[MAXT] = {NULL}; /* channels downtree (may be empty) */ int PPIF::slvcnt[MAXT]; /* number of processors in subtree */ -/****************************************************************************/ -/* */ -/* forward declarations of functions used before they are defined */ -/* */ -/****************************************************************************/ - -int SendSync (void* v, void *data, int size); -int RecvSync (void* v, void *data, int size); - /****************************************************************************/ /* */ /* routines for handling virtual channels */ @@ -147,19 +140,19 @@ int RecvSync (void* v, void *data, int size); static VChannelPtr NewVChan (int p, int id) { - MPIVChannelPtr myChan = (MPIVChannelPtr)malloc(sizeof(MPIVChannel)); + VChannelPtr myChan = new PPIF::VChannel; myChan->p = p; myChan->chanid = id; - return (myChan); + return myChan; } static void DeleteVChan (VChannelPtr myChan) { - free(myChan); + delete myChan; } @@ -197,28 +190,10 @@ static void Factor (int N, int *pn, int *pm) } - -static int PPIFBeganMPI=0; /* remember that PPIF started MPI */ - - -int PPIF::InitPPIF (int *argcp, char ***argvp) +int PPIF::InitPPIF (int *, char ***) { int i, succ, sonr, sonl; - MPI_Status status; - int mpierror, mpiinitialized; - - /* the following is due to Klaus-Dieter Oertel, 961016; - (original idea from the developers of the PetSc library) */ - /* ppif checks whether MPI has been started by another - library and starts it only if necessary. */ - mpierror = MPI_Initialized(&mpiinitialized); - if (mpierror) MPI_Abort(MPI_COMM_WORLD, mpierror); - if (!mpiinitialized) - { - mpierror = MPI_Init (argcp, argvp); - if (mpierror) MPI_Abort( MPI_COMM_WORLD, mpierror); - PPIFBeganMPI = 1; - } + MPI_Comm_rank (COMM, &me); MPI_Comm_size (COMM, &procs); @@ -269,7 +244,7 @@ int PPIF::InitPPIF (int *argcp, char ***argvp) for(i=0; i<degree; i++) { MPI_Recv ((void *) &(slvcnt[i]), (int) sizeof(int), MPI_BYTE, - ((MPIVChannel*)downtree[i])->p, ID_TREE, COMM, &status); + downtree[i]->p, ID_TREE, COMM, MPI_STATUS_IGNORE); succ += slvcnt[i]; } if (me>0) @@ -283,15 +258,6 @@ int PPIF::InitPPIF (int *argcp, char ***argvp) int PPIF::ExitPPIF () { - int mpierror; - - if (PPIFBeganMPI) - { - mpierror = MPI_Finalize(); - if (mpierror) MPI_Abort(MPI_COMM_WORLD, mpierror); - PPIFBeganMPI = 0; - } - /* Deallocate tree structure */ DeleteVChan(uptree); uptree = NULL; @@ -377,33 +343,32 @@ VChannelPtr PPIF::ConnSync (int p, int id) return (NewVChan (p, id) ); } -int PPIF::DiscSync (void* v) +int PPIF::DiscSync (VChannelPtr v) { - VChannelPtr vc = (VChannelPtr)v; - DeleteVChan (vc); + DeleteVChan(v); return (0); } -int PPIF::SendSync (void* v, void *data, int size) +int PPIF::SendSync (VChannelPtr v, void *data, int size) { if (MPI_SUCCESS == MPI_Ssend (data, size, MPI_BYTE, - ((MPIVChannel*)v)->p, ((MPIVChannel*)v)->chanid, COMM) ) + v->p, v->chanid, COMM) ) return (size); else return (-1); } -int PPIF::RecvSync (void* v, void *data, int size) +int PPIF::RecvSync (VChannelPtr v, void *data, int size) { int count = -1; MPI_Status status; if (MPI_SUCCESS == MPI_Recv (data, size, MPI_BYTE, - ((MPIVChannel*)v)->p, ((MPIVChannel*)v)->chanid, COMM, &status) ) + v->p, v->chanid, COMM, &status) ) MPI_Get_count (&status, MPI_BYTE, &count); return (count); @@ -422,161 +387,99 @@ VChannelPtr PPIF::ConnASync (int p, int id) return (NewVChan (p,id) ); } -int PPIF::InfoAConn (void* v) +int PPIF::InfoAConn (VChannelPtr v) { return (v ? 1 : -1); } -int PPIF::DiscASync (void* v) +int PPIF::DiscASync (VChannelPtr v) { - DeleteVChan ((MPIVChannel*)v); + DeleteVChan (v); return (PPIF_SUCCESS); } -int PPIF::InfoADisc (void* v) +int PPIF::InfoADisc (VChannelPtr v) { return (true); } -#define REQUEST_HEAP - -msgid PPIF::SendASync (void* v, void *data, int size, int *error) - +msgid PPIF::SendASync (VChannelPtr v, void *data, int size, int *error) { -# ifdef REQUEST_HEAP - MPI_Request *req; + msgid m = new PPIF::Msg; - if (req = (MPI_Request*)malloc (sizeof (MPI_Request) ) ) + if (m) { if (MPI_SUCCESS == MPI_Isend (data, size, MPI_BYTE, - ((MPIVChannel*)v)->p, ((MPIVChannel*)v)->chanid, COMM, req) ) + v->p, v->chanid, COMM, &m->req) ) { *error = false; - return ((msgid) req); + return m; } } -# else - MPI_Request Req; - if (MPI_SUCCESS == MPI_Isend (data, size, MPI_BYTE, - ((MPIVChannel*)v)->p, ((MPIVChannel*)v)->chanid, COMM, &Req) ) - { - *error = false; - return ((msgid) Req); - } -# endif - *error = true; return NULL; } -msgid PPIF::RecvASync (void* v, void *data, int size, int *error) +msgid PPIF::RecvASync (VChannelPtr v, void *data, int size, int *error) { -# ifdef REQUEST_HEAP - MPI_Request *req; + msgid m = new PPIF::Msg; - if (req = (MPI_Request*)malloc (sizeof (MPI_Request) ) ) + if (m) { if (MPI_SUCCESS == MPI_Irecv (data, size, MPI_BYTE, - ((MPIVChannel*)v)->p, ((MPIVChannel*)v)->chanid, COMM, req) ) + v->p, v->chanid, COMM, &m->req) ) { *error = false; - return ((msgid) req); + return m; } } -# else - MPI_Request Req; - - if (MPI_SUCCESS == MPI_Irecv (data, size, MPI_BYTE, - ((MPIVChannel*)v)->p, ((MPIVChannel*)v)->chanid, COMM, &Req) ) - { - *error = false; - return ((msgid) Req); - } - -# endif - *error = true; return (NULL); } -int PPIF::InfoASend (void* v, msgid m) +int PPIF::InfoASend (VChannelPtr v, msgid m) { - MPI_Status status; int complete; -# ifdef REQUEST_HEAP if (m) { - if (MPI_SUCCESS == MPI_Test ((MPI_Request *) m, &complete, &status) ) + if (MPI_SUCCESS == MPI_Test (&m->req, &complete, MPI_STATUS_IGNORE) ) { - if (complete) free (m); + if (complete) + delete m; return (complete); /* complete is true for completed send, false otherwise */ } } -# else - MPI_Request Req = (MPI_Request) m; - - if (MPI_SUCCESS == MPI_Test (&Req, &complete, &status) ) - { - return (complete); /* complete is true for completed send, false otherwise */ - } - -# endif - return (-1); /* return -1 for FAILURE */ } -int PPIF::InfoARecv (void* v, msgid m) +int PPIF::InfoARecv (VChannelPtr v, msgid m) { - MPI_Status status; int complete; -# ifdef REQUEST_HEAP if (m) { - if (MPI_SUCCESS == MPI_Test ((MPI_Request *) m, &complete, &status) ) + if (MPI_SUCCESS == MPI_Test (&m->req, &complete, MPI_STATUS_IGNORE) ) { - if (complete) free (m); + if (complete) + delete m; return (complete); /* complete is true for completed receive, false otherwise */ } } -# else - MPI_Request Req = (MPI_Request) m; - - if (MPI_SUCCESS == MPI_Test (&Req, &complete, &status) ) - { - return (complete); /* complete is true for completed receive, false otherwise */ - } - -# endif - return (-1); /* return -1 for FAILURE */ } - - -/****************************************************************************/ -/* */ -/* Miscellaneous */ -/* */ -/****************************************************************************/ - -void PPIF::PrintHostMessage (const char *s) - -{ - printf ("%s", s); -} diff --git a/parallel/ppif/ppif.h b/parallel/ppif/ppif.h index 8f6ea190c1064701fdbfd7188fa0cd0b71b0722c..654a63e73f7d46d7e5a3c886b8c0e8b7649178fe 100644 --- a/parallel/ppif/ppif.h +++ b/parallel/ppif/ppif.h @@ -34,18 +34,31 @@ /* */ /****************************************************************************/ -typedef void *VChannelPtr; /* dummy definition, any pointer type is ok */ -typedef void *msgid; /* dummy definition, any pointer type is ok */ -#define NO_MSGID ((msgid)-1L) /* a special value that should never be re- */ - /* turned as a msgid, like NULL for pointers */ +namespace PPIF { + +/** + * opaque type for communication channels + */ +struct VChannel; + +/** + * opaque type for messages + */ +struct Msg; + +} /* namespace PPIF */ + + +using VChannelPtr = PPIF::VChannel*; +using msgid = PPIF::Msg*; + +constexpr static msgid NO_MSGID = nullptr; namespace PPIF { enum directions {north,east,south,west,up,down}; -#define RAND_MSG_SIZE 128 /* max size of random messages */ - #define PPIF_SUCCESS 0 /* Return value for success */ #define PPIF_FAILURE 1 /* Return value for failure */ @@ -104,9 +117,6 @@ int InfoADisc (VChannelPtr vc); int InfoASend (VChannelPtr vc, msgid m); int InfoARecv (VChannelPtr vc, msgid m); -/* miscellaneous */ -void PrintHostMessage (const char *s); - } // end namespace PPIF