// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LGPL-2.1-or-later // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: /****************************************************************************/ /* */ /* File: pgmcheck.c */ /* */ /* Purpose: functions for checking parallel consistency */ /* */ /* Author: Stefan Lang */ /* Institut fuer Computeranwendungen III */ /* Universitaet Stuttgart */ /* Pfaffenwaldring 27 */ /* 70550 Stuttgart */ /* email: birken@ica3.uni-stuttgart.de */ /* phone: 0049-(0)711-685-7003 */ /* fax : 0049-(0)711-685-7000 */ /* */ /* History: 980204 sl begin */ /* */ /* Remarks: */ /* */ /****************************************************************************/ #ifdef ModelP /****************************************************************************/ /* */ /* include files */ /* system include files */ /* application include files */ /* */ /****************************************************************************/ #include #include #include "parallel.h" #include #include #include #include #include #include #include #include /* UG namespaces: */ USING_UG_NAMESPACES /* PPIF namespace: */ using namespace PPIF; /****************************************************************************/ /* */ /* defines in the following order */ /* */ /* compile time constants defining static data size (i.e. arrays) */ /* other constants */ /* macros */ /* */ /****************************************************************************/ #define CHECK_OBJECT_PRIO(o,prio,master,ghost,id,s,_nerr_) \ do { \ if (USED(o)==1 && ! master (o)) \ { \ UserWriteF("MASTER %s=" id ## _FMTX " has WRONG prio=%d\n", \ s, id ## _PRTX(o),prio(o)); \ _nerr_++; \ } \ if (USED( o )==0 && ! ghost ( o )) \ { \ UserWriteF("GHOST %s=" id ## _FMTX " has WRONG prio=%d\n", \ s, id ## _PRTX( o ),prio(o)); \ _nerr_++; \ } \ } while (0) /****************************************************************************/ /* */ /* data structures used in this source file (exported data structures are */ /* in the corresponding include file!) */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* definition of exported global variables */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* definition of variables global to this source file only (static!) */ /* */ /****************************************************************************/ /* count for errors to report from communication scatter functions */ static INT check_distributed_objects_errors = 0; /****************************************************************************/ /* */ /* forward declarations of functions used before they are defined */ /* */ /****************************************************************************/ /****************************************************************************/ /* CheckProcListCons - SYNOPSIS: INT CheckProcListCons (const DDD_InfoProcListRange& proclist, DDD_PRIO uniqueTag); PARAMETERS: . proclist . uniqueTag DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ INT NS_DIM_PREFIX CheckProcListCons (const DDD_InfoProcListRange& proclist, DDD_PRIO uniqueTag) { int nunique = 0; /* check uniqueness */ for (auto&& [proc, prio] : proclist) { if (prio == uniqueTag) ++nunique; } /* nunique must be 1 for master elements */ /* nunique can be 0/1 for (inner) nodes */ /* with PrioBorder/PrioMaster */ return nunique; } /****************************************************************************/ /* ListProcList - SYNOPSIS: INT ListProcList (const DDD_InfoProcListRange& proclist, DDD_PRIO uniqueTag); PARAMETERS: . proclist . uniqueTag DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ static INT ListProcList (const DDD_InfoProcListRange& proclist, DDD_PRIO uniqueTag) { for (auto&& [proc, prio] : proclist) { if (prio == uniqueTag) UserWriteF(" proc=%d", proc); } return 0; } /****************************************************************************/ /* CheckVectorPrio - SYNOPSIS: INT CheckVectorPrio (ELEMENT *theElement, VECTOR *theVector); PARAMETERS: . theElement . theVector DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ static INT CheckVectorPrio (DDD::DDDContext& context, ELEMENT *theElement, VECTOR *theVector) { INT nmaster; INT nerrors = 0; /* check vector prio */ CHECK_OBJECT_PRIO(theVector,PRIO,MASTER,GHOST,VINDEX,"Vector",nerrors); /* master copy has to be unique */ const auto& proclist = DDD_InfoProcListRange(context, PARHDR(theVector)); if ((nmaster = CheckProcListCons(proclist, PrioMaster)) > 1) { UserWriteF("VECTOR=" ID_FMTX " ERROR: master copy not unique, nmaster=%d:", ID_PRTX(theVector),nmaster); ListProcList(proclist, PrioMaster); UserWriteF("\n"); nerrors++; } return nerrors; } /****************************************************************************/ /* CheckNodePrio - SYNOPSIS: INT CheckNodePrio (ELEMENT *theElement, NODE *theNode); PARAMETERS: . theElement . theNode DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ static INT CheckNodePrio (DDD::DDDContext& context, ELEMENT *theElement, NODE *theNode) { INT nmaster; INT nerrors = 0; /* check node prio */ CHECK_OBJECT_PRIO(theNode,PRIO,MASTER,GHOST,ID,"NODE",nerrors); /* master copy has to be unique */ const auto& proclist = DDD_InfoProcListRange(context, PARHDR(theNode)); if ((nmaster = CheckProcListCons(proclist, PrioMaster)) > 1) { UserWriteF("NODE=" ID_FMTX " ERROR: master copy not unique, nmaster=%d:", ID_PRTX(theNode),nmaster); ListProcList(proclist, PrioMaster); UserWriteF("\n"); nerrors++; } return(nerrors); } /****************************************************************************/ /* CheckEdgePrio - SYNOPSIS: INT CheckEdgePrio (ELEMENT *theElement, EDGE *theEdge); PARAMETERS: . theElement . theEdge DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ static INT CheckEdgePrio (DDD::DDDContext& context, ELEMENT *theElement, EDGE *theEdge) { INT nerrors = 0; #ifdef UG_DIM_3 INT nmaster; /* check edge prio */ CHECK_OBJECT_PRIO(theEdge,PRIO,MASTER,GHOST,ID,"EDGE",nerrors); /* master copy has to be unique */ const auto& proclist = DDD_InfoProcListRange(context, PARHDR(theEdge)); if ((nmaster = CheckProcListCons(proclist, PrioMaster)) > 1) { UserWriteF("EDGE=" EDID_FMTX " ERROR: master copy not unique, nmaster=%d:", EDID_PRTX(theEdge),nmaster); ListProcList(proclist, PrioMaster); UserWriteF("\n"); nerrors++; } #endif if (ddd_ctrl(context).edgeData) if (EDVECTOR(theEdge) != NULL) nerrors += CheckVectorPrio(context, theElement,EDVECTOR(theEdge)); return(nerrors); } /****************************************************************************/ /* CheckElementPrio - SYNOPSIS: INT CheckElementPrio (ELEMENT *theElement); PARAMETERS: . theElement DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ static INT CheckElementPrio (DDD::DDDContext& context, ELEMENT *theElement) { INT i,nmaster,prio,valid_copy; INT nerrors = 0; NODE *theNode; EDGE *theEdge; ELEMENT *SonList[MAX_SONS]; const auto& me = context.me(); if (PARTITION(theElement)==me && !EMASTER(theElement)) { UserWriteF(PFMT "#FATAL# MASTER ELEM=" EID_FMTX " has WRONG part=%d prio=%d\n", me,EID_PRTX(theElement),PARTITION(theElement),EPRIO(theElement)); nerrors++; } if (PARTITION(theElement)!=me && !EGHOST(theElement)) { UserWriteF(PFMT "#FATAL# GHOST ELEM=" EID_FMTX " has WRONG part=%d prio=%d\n", me,EID_PRTX(theElement),PARTITION(theElement),EPRIO(theElement)); nerrors++; /* test ghost prio */ prio = 0; for (i=0; i0) remotegid = ((DDD_GID *)data)[i]-1; if (MidNode != NULL) { if (remotegid != GID(MidNode)) { UserWriteF("EDGE=" ID_FMTX " #ERROR#: MIDNODE=" ID_FMTX " gids don't match " "local=%08x remote=%08x remoteproc/prio=%d/%d\n", ID_PRTX(theEdge),ID_PRTX(MidNode), GID(MidNode),remotegid,proc,prio); check_distributed_objects_errors++; assert(0); } } else { if (remotegid != 0) { UserWriteF("EDGE=" ID_FMTX " #ERROR#: MIDNODE=NULL gids don't match " "local=%08x remote=%08x remoteproc/prio=%d/%d\n", ID_PRTX(theEdge),0,remotegid,proc,prio); check_distributed_objects_errors++; assert(0); } } i++; return 0; } #endif static INT CheckDistributedObjects (GRID *theGrid) { auto& context = theGrid->dddContext(); const auto& dddctrl = ddd_ctrl(context); INT nerrors; #ifdef UG_DIM_2 INT size = MAX_CORNERS_OF_ELEM; /* compare the 3/4 node ids */ #endif #ifdef UG_DIM_3 INT size = MAX_CORNERS_OF_ELEM+MAX_EDGES_OF_ELEM; /* compare 8 nodes + 12 edges */ #endif check_distributed_objects_errors = 0; // void DDD_IFAOnewayX (DDD::DDDContext&, DDD_IF, DDD_ATTR, DDD_IF_DIR, size_t, ComProcXPtr, ComProcXPtr); DDD_IFAOnewayX(context, dddctrl.ElementSymmVHIF,GRID_ATTR(theGrid),IF_BACKWARD,size*sizeof(DDD_GID), Gather_ElemObjectGids, Scatter_ElemObjectGids); #ifdef UG_DIM_3 if (0) DDD_IFAOnewayX(context, dddctrl.BorderEdgeSymmIF,GRID_ATTR(theGrid),IF_BACKWARD,3*sizeof(DDD_GID), Gather_EdgeObjectGids, Scatter_EdgeObjectGids); #endif nerrors = check_distributed_objects_errors; return(nerrors); } /****************************************************************************/ /* CheckInterfaces - SYNOPSIS: INT CheckInterfaces (GRID *theGrid); PARAMETERS: . theGrid DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ INT NS_DIM_PREFIX CheckInterfaces (GRID *theGrid) { auto& context = theGrid->dddContext(); auto& dddctrl = ddd_ctrl(context); INT i,j; ELEMENT *theElement; NODE *theNode; EDGE *theEdge; int nerrors = 0; /* reset USED flag of all grid objects */ /* set USED flag of master grid objects */ for (j=0; j<2; j++) { for (theElement =(j==0 ? PFIRSTELEMENT(theGrid) : FIRSTELEMENT(theGrid)); theElement!=NULL; theElement=SUCCE(theElement)) { SETUSED(theElement,j); if (dddctrl.elemData) if (EVECTOR(theElement) != NULL) SETUSED(EVECTOR(theElement),j); #ifdef UG_DIM_3 if (dddctrl.sideData) { for (i=0; idddContext(), theElement); } /* check uniqueness of global ids for distributed nodes and edges */ nerrors += CheckDistributedObjects(theGrid); /* check ddd interface consistency */ DDD_SetOption(theGrid->dddContext(), OPT_QUIET_CONSCHECK, OPT_ON); nerrors += DDD_ConsCheck(theGrid->dddContext()); DDD_SetOption(theGrid->dddContext(), OPT_QUIET_CONSCHECK, OPT_OFF); return(nerrors); } #endif