| 1 |
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 4 |
// vi: set et ts=4 sw=2 sts=2: |
| 5 |
/****************************************************************************/ |
| 6 |
/* */ |
| 7 |
/* File: ifobjsc.c */ |
| 8 |
/* */ |
| 9 |
/* Purpose: routines concerning interfaces between processors */ |
| 10 |
/* part 4: routines for creation and management of */ |
| 11 |
/* object shortcut tables */ |
| 12 |
/* */ |
| 13 |
/* Author: Klaus Birken */ |
| 14 |
/* Rechenzentrum Uni Stuttgart */ |
| 15 |
/* Universitaet Stuttgart */ |
| 16 |
/* Allmandring 30 */ |
| 17 |
/* 70550 Stuttgart */ |
| 18 |
/* internet: [email protected] */ |
| 19 |
/* */ |
| 20 |
/* History: 96/01/24 kb copied from ifcreate.c */ |
| 21 |
/* */ |
| 22 |
/* Remarks: */ |
| 23 |
/* */ |
| 24 |
/****************************************************************************/ |
| 25 |
|
| 26 |
/****************************************************************************/ |
| 27 |
/* */ |
| 28 |
/* include files */ |
| 29 |
/* system include files */ |
| 30 |
/* application include files */ |
| 31 |
/* */ |
| 32 |
/****************************************************************************/ |
| 33 |
|
| 34 |
/* standard C library */ |
| 35 |
#include <config.h> |
| 36 |
#include <cstdlib> |
| 37 |
#include <cstdio> |
| 38 |
|
| 39 |
#include <dune/uggrid/parallel/ddd/dddi.h> |
| 40 |
#include "if.h" |
| 41 |
|
| 42 |
USING_UG_NAMESPACE |
| 43 |
|
| 44 |
START_UGDIM_NAMESPACE |
| 45 |
|
| 46 |
/****************************************************************************/ |
| 47 |
/* */ |
| 48 |
/* definition of static variables */ |
| 49 |
/* */ |
| 50 |
/****************************************************************************/ |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
/****************************************************************************/ |
| 55 |
/* */ |
| 56 |
/* routines */ |
| 57 |
/* */ |
| 58 |
/****************************************************************************/ |
| 59 |
|
| 60 |
|
| 61 |
/* |
| 62 |
convert cpl-IF-table into obj-IF-table |
| 63 |
*/ |
| 64 |
static void IFComputeShortcutTable(DDD::DDDContext& context, DDD_IF ifId) |
| 65 |
{ |
| 66 |
auto& theIF = context.ifCreateContext().theIf; |
| 67 |
|
| 68 |
int nItems = theIF[ifId].nItems; |
| 69 |
COUPLING **cpls = theIF[ifId].cpl; |
| 70 |
IFObjPtr *objs = theIF[ifId].obj; |
| 71 |
|
| 72 |
/* mark obj-shortcut-table as valid */ |
| 73 |
theIF[ifId].objValid = true; |
| 74 |
|
| 75 |
if (nItems==0) |
| 76 |
return; |
| 77 |
|
| 78 |
/* fill in object pointers, this is the 4-fold indirection step */ |
| 79 |
for(int i = 0; i < nItems; ++i) |
| 80 |
{ |
| 81 |
objs[i] = OBJ_OBJ(context, cpls[i]->obj); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
/****************************************************************************/ |
| 87 |
|
| 88 |
|
| 89 |
/* |
| 90 |
create direct link from ifHead and ifAttr to objects, |
| 91 |
avoid one indirect addressing step across couplings. |
| 92 |
each cpl-entry in an interface has one corresponding obj-entry |
| 93 |
*/ |
| 94 |
void IFCreateObjShortcut(DDD::DDDContext& context, DDD_IF ifId) |
| 95 |
{ |
| 96 |
auto& theIF = context.ifCreateContext().theIf; |
| 97 |
|
| 98 |
COUPLING **cplarray = theIF[ifId].cpl; |
| 99 |
IFObjPtr *objarray; |
| 100 |
IF_PROC *ifHead; |
| 101 |
|
| 102 |
/* dont create shortcuts for STD_INTERFACE */ |
| 103 |
if (ifId==STD_INTERFACE) |
| 104 |
return; |
| 105 |
|
| 106 |
/* are there any items? */ |
| 107 |
if (theIF[ifId].nItems == 0) |
| 108 |
return; |
| 109 |
|
| 110 |
/* get memory for addresses of objects inside IF */ |
| 111 |
objarray = (IFObjPtr *) AllocIF(sizeof(IFObjPtr)*theIF[ifId].nItems); |
| 112 |
if (objarray==NULL) |
| 113 |
throw std::bad_alloc(); |
| 114 |
|
| 115 |
theIF[ifId].obj = objarray; |
| 116 |
|
| 117 |
IFComputeShortcutTable(context, ifId); |
| 118 |
|
| 119 |
|
| 120 |
ForIF(context, ifId, ifHead) |
| 121 |
{ |
| 122 |
IF_ATTR *ifAttr; |
| 123 |
|
| 124 |
/* compute pointers to subarrays */ |
| 125 |
ifHead->obj = objarray + (ifHead->cpl - cplarray); |
| 126 |
ifHead->objAB = objarray + (ifHead->cplAB - cplarray); |
| 127 |
ifHead->objBA = objarray + (ifHead->cplBA - cplarray); |
| 128 |
ifHead->objABA = objarray + (ifHead->cplABA - cplarray); |
| 129 |
|
| 130 |
|
| 131 |
/* compute pointers from ifAttrs to subarrays */ |
| 132 |
for(ifAttr=ifHead->ifAttr; ifAttr!=0; ifAttr=ifAttr->next) |
| 133 |
{ |
| 134 |
ifAttr->objAB = objarray + (ifAttr->cplAB - cplarray); |
| 135 |
ifAttr->objBA = objarray + (ifAttr->cplBA - cplarray); |
| 136 |
ifAttr->objABA = objarray + (ifAttr->cplABA - cplarray); |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
/****************************************************************************/ |
| 143 |
|
| 144 |
|
| 145 |
/* |
| 146 |
if object addresses in memory are changed, then the shortcut-tables |
| 147 |
will get invalid. this routine does the invalidation. |
| 148 |
*/ |
| 149 |
void IFInvalidateShortcuts(DDD::DDDContext& context, DDD_TYPE invalid_type) |
| 150 |
{ |
| 151 |
auto& theIF = context.ifCreateContext().theIf; |
| 152 |
const auto& nIFs = context.ifCreateContext().nIfs; |
| 153 |
|
| 154 |
/* test all interfaces */ |
| 155 |
for(int i = 0; i < nIFs; ++i) |
| 156 |
{ |
| 157 |
if (i==STD_INTERFACE) |
| 158 |
continue; |
| 159 |
|
| 160 |
if (theIF[i].objValid) |
| 161 |
{ |
| 162 |
/* determine whether object belongs to IF */ |
| 163 |
if ((1<<invalid_type) & theIF[i].maskO) |
| 164 |
{ |
| 165 |
/* yes, invalidate interface */ |
| 166 |
theIF[i].objValid = false; |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
/****************************************************************************/ |
| 175 |
|
| 176 |
|
| 177 |
/* |
| 178 |
check if shortcut-table is valid and recompute, if necessary |
| 179 |
*/ |
| 180 |
void IFCheckShortcuts (DDD::DDDContext& context, DDD_IF ifId) |
| 181 |
{ |
| 182 |
if (ifId==STD_INTERFACE) |
| 183 |
return; |
| 184 |
|
| 185 |
auto& theIF = context.ifCreateContext().theIf; |
| 186 |
if (! theIF[ifId].objValid) |
| 187 |
{ |
| 188 |
/* |
| 189 |
sprintf(cBuffer, "%04d: IFComputeShortcutTable IF=%d\n", context.me(), ifId); |
| 190 |
DDD_PrintDebug(cBuffer); |
| 191 |
*/ |
| 192 |
|
| 193 |
IFComputeShortcutTable(context, ifId); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
/****************************************************************************/ |
| 198 |
|
| 199 |
END_UGDIM_NAMESPACE |