// 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: priority.c */ /* */ /* Purpose: functions for managing priorities of distributed objects */ /* */ /* Author: Stefan Lang */ /* Institut fuer Computeranwendungen III */ /* Universitaet Stuttgart */ /* Pfaffenwaldring 27 */ /* 70550 Stuttgart */ /* email: birken@ica3.uni-stuttgart.de */ /* */ /* History: 980201 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 */ /* */ /****************************************************************************/ /* macros for merge new priority with objects existing one */ /* valid only for all types of ghost priorities */ #define PRIO_CALC(e) ((USED(e) && THEFLAG(e)) ? PrioVHGhost : \ (THEFLAG(e)) ? PrioVGhost : (USED(e)) ? \ PrioHGhost : (assert(0),0)) #define SETPRIOPV SETPRIOX /* macros for setting object priorities with related objects */ inline void NODE_PRIORITY_SET(DDD::DDDContext& context, GRID* grid, NODE* node, INT prio) { /* set priorities of node */ SETPRIOX(context, node, prio); } inline void PRIO_SET_EDGE(DDD::DDDContext& context, EDGE* edge, INT prio) { SETPRIOX(context, edge, prio); } inline void EDGE_PRIORITY_SET(DDD::DDDContext& context, GRID* grid, EDGE* edge, INT prio) { /* set priorities of node for 3D */ PRIO_SET_EDGE(context, edge, prio); } /****************************************************************************/ /* */ /* data structures used in this source file (exported data structures are */ /* in the corresponding include file!) */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* definition of exported global variables */ /* */ /****************************************************************************/ /****************************************************************************/ /* */ /* forward declarations of functions used before they are defined */ /* */ /****************************************************************************/ /* for all PrioMaster-nodes with remote copies, set exactly one to PrioMaster, the other copies to PrioBorder in order to establish the BorderNodeIF. this is done for one grid. */ /****************************************************************************/ /* ComputeNodeBorderPrios - SYNOPSIS: static int ComputeNodeBorderPrios (DDD_OBJ obj); PARAMETERS: . obj - DESCRIPTION: RETURN VALUE: int */ /****************************************************************************/ static int ComputeNodeBorderPrios (DDD::DDDContext& context, DDD_OBJ obj) { NODE *node = (NODE *)obj; int min_proc = context.procs(); /* minimum processor number will get Master-node, all others get Border-nodes */ for (auto&& [proc, prio] : DDD_InfoProcListRange(context, PARHDR(node))) { if (prio == PrioMaster && proc < min_proc) min_proc = proc; } if (min_proc == context.procs()) return(0); if (context.me() != min_proc) SETPRIO(context, node, PrioBorder); return 0; } /****************************************************************************/ /* ComputeVectorBorderPrios - SYNOPSIS: static int ComputeVectorBorderPrios (DDD_OBJ obj); PARAMETERS: . obj - DESCRIPTION: RETURN VALUE: int */ /****************************************************************************/ static int ComputeVectorBorderPrios (DDD::DDDContext& context, DDD_OBJ obj) { VECTOR *vector = (VECTOR *)obj; int min_proc = context.procs(); /* minimum processor number will get Master-node, all others get Border-nodes */ for (auto&& [proc, prio] : DDD_InfoProcListRange(context, PARHDR(vector))) { if (prio == PrioMaster && proc < min_proc) min_proc = proc; } if (min_proc == context.procs()) return(0); if (context.me() != min_proc) SETPRIO(context, vector, PrioBorder); return 0; } /****************************************************************************/ /* ComputeEdgeBorderPrios - SYNOPSIS: static int ComputeEdgeBorderPrios (DDD_OBJ obj); PARAMETERS: . obj - DESCRIPTION: RETURN VALUE: void */ /****************************************************************************/ static int ComputeEdgeBorderPrios (DDD::DDDContext& context, DDD_OBJ obj) { EDGE *edge = (EDGE *)obj; int min_proc = context.procs(); /* minimum processor number will get Master-node, all others get Border-nodes */ for (auto&& [proc, prio] : DDD_InfoProcListRange(context, PARHDR(edge))) { if (prio == PrioMaster && proc < min_proc) min_proc = proc; } if (min_proc == context.procs()) return(0); if (context.me() != min_proc) SETPRIO(context, edge, PrioBorder); return 0; } /****************************************************************************/ /* SetGhostObjectPriorities - SYNOPSIS: void SetGhostObjectPriorities (GRID *theGrid); PARAMETERS: . theGrid DESCRIPTION: RETURN VALUE: void */ /****************************************************************************/ void NS_DIM_PREFIX SetGhostObjectPriorities (GRID *theGrid) { ELEMENT *theElement,*theNeighbor,*SonList[MAX_SONS]; NODE *theNode; EDGE *theEdge; INT i,prio,hghost,vghost; auto& context = theGrid->dddContext(); const auto& me = context.me(); /* reset USED flag for objects of ghostelements */ for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement)) { SETUSED(theElement,0); SETTHEFLAG(theElement,0); for (i=0; idddContext(); const auto& dddctrl = ddd_ctrl(context); DDD_IFAExecLocal(context, dddctrl.BorderNodeSymmIF,GRID_ATTR(theGrid), ComputeNodeBorderPrios); /* TODO: distinguish two cases: 1. only nodevectors then setting of vector prios can be done in ComputeNodeBorderPrios without extra communiction 2. with other vectortypes (side and/or edgevectors) use ComputeVectorBorderPrios */ DDD_IFAExecLocal(context, dddctrl.BorderVectorSymmIF,GRID_ATTR(theGrid), ComputeVectorBorderPrios); DDD_IFAExecLocal(context, dddctrl.BorderEdgeSymmIF,GRID_ATTR(theGrid), ComputeEdgeBorderPrios); return(GM_OK); } /****************************************************************************/ /* SetGridBorderPriorities - SYNOPSIS: INT SetGridBorderPriorities (GRID *theGrid); PARAMETERS: . theGrid DESCRIPTION: RETURN VALUE: INT */ /****************************************************************************/ INT NS_DIM_PREFIX SetGridBorderPriorities (GRID *theGrid) { /* set border priorities on next higher level */ if (SetBorderPriorities(UPGRID(theGrid)) != GM_OK) return(GM_FATAL); return(GM_OK); } #endif