Debian Codegraph @

dune/uggrid/parallel/ddd/join/join.cc

raw
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: join.c */
8 /* */
9 /* Purpose: main module for object join environment */
10 /* */
11 /* Author: Klaus Birken */
12 /* Institut fuer Computeranwendungen III */
13 /* Universitaet Stuttgart */
14 /* Pfaffenwaldring 27 */
15 /* 70569 Stuttgart */
16 /* email: [email protected] */
17 /* phone: 0049-(0)711-685-7007 */
18 /* fax : 0049-(0)711-685-7000 */
19 /* */
20 /* History: 980122 kb begin */
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 #include <cstring>
39
40 #include <dune/common/stdstreams.hh>
41
42 #include <dune/uggrid/parallel/ddd/dddi.h>
43
44 USING_UG_NAMESPACE
45
46 START_UGDIM_NAMESPACE
47
48 /*
49 NOTE: all container-classes from ooppcc.h are implemented in this
50 source file by setting the following define.
51 */
52 #define ContainerImplementation
53 #define _CHECKALLOC(ptr) assert(ptr!=NULL)
54
55
56 END_UGDIM_NAMESPACE
57
58 #include "join.h"
59
60 START_UGDIM_NAMESPACE
61
62
63 /****************************************************************************/
64 /* */
65 /* class member function implementations */
66 /* */
67 /****************************************************************************/
68
69 #define ClassName JIJoin
70
71 /*
72 compare-method in order to eliminate double JIJoin-items.
73
74 the items are sorted according to key (dest,remote_gid),
75 all in ascending order.
76 */
77 int Method(Compare) (ClassPtr item1, ClassPtr item2, const DDD::DDDContext*)
78 {
79 if (item1->dest < item2->dest) return(-1);
80 if (item1->dest > item2->dest) return(1);
81
82 if (item1->new_gid < item2->new_gid) return(-1);
83 if (item1->new_gid > item2->new_gid) return(1);
84
85
86 /* items have equal gid and dest, so they are considered as equal. */
87 return(0);
88 }
89
90
91 void Method(Print) (ParamThis _PRINTPARAMS)
92 {
93 fprintf(fp, "JIJoin local_gid=" OBJ_GID_FMT " dest=%d new_gid=" DDD_GID_FMT "\n",
94 OBJ_GID(This->hdr), This->dest, This->new_gid);
95 }
96
97 #undef ClassName
98
99
100
101
102 #define ClassName JIAddCpl
103
104 /*
105 compare-method in order to eliminate double JIAddCpl-items.
106
107 the items are sorted according to key (dest,gid),
108 all in ascending order.
109 */
110 int Method(Compare) (ClassPtr item1, ClassPtr item2, const DDD::DDDContext*)
111 {
112 if (item1->dest < item2->dest) return(-1);
113 if (item1->dest > item2->dest) return(1);
114
115 if (item1->te.gid < item2->te.gid) return(-1);
116 if (item1->te.gid > item2->te.gid) return(1);
117
118 if (item1->te.proc < item2->te.proc) return(-1);
119 if (item1->te.proc > item2->te.proc) return(1);
120
121
122 /* items have equal gid and dest, so they are considered as equal. */
123 return(0);
124 }
125
126
127 void Method(Print) (ParamThis _PRINTPARAMS)
128 {
129 fprintf(fp, "JIAddCpl gid=" DDD_GID_FMT " dest=%d proc=%d prio=%d\n",
130 This->te.gid, This->dest, This->te.proc, This->te.prio);
131 }
132
133 #undef ClassName
134
135
136
137
138 /****************************************************************************/
139 /* */
140 /* routines */
141 /* */
142 /****************************************************************************/
143
144
145 /*
146 management functions for JoinMode.
147
148 these functions control the mode the join-module is
149 currently in. this is used for error detection, but
150 also for correct detection of coupling inconsistencies
151 and recovery.
152 */
153
154 const char *JoinModeName(JoinMode mode)
155 {
156 switch(mode)
157 {
158 case JoinMode::JMODE_IDLE : return "idle-mode";
159 case JoinMode::JMODE_CMDS : return "commands-mode";
160 case JoinMode::JMODE_BUSY : return "busy-mode";
161 }
162 return "unknown-mode";
163 }
164
165
166 static void JoinSetMode (DDD::DDDContext& context, JoinMode mode)
167 {
168 auto& ctx = context.joinContext();
169
170 ctx.joinMode = mode;
171
172 # if DebugJoin<=8
173 Dune::dinfo << "JoinMode=" << JoinModeName(ctx.joinMode) << "\n";
174 # endif
175 }
176
177
178 static JoinMode JoinSuccMode (JoinMode mode)
179 {
180 switch(mode)
181 {
182 case JoinMode::JMODE_IDLE : return JoinMode::JMODE_CMDS;
183 case JoinMode::JMODE_CMDS : return JoinMode::JMODE_BUSY;
184 case JoinMode::JMODE_BUSY : return JoinMode::JMODE_IDLE;
185 }
186 DUNE_THROW(Dune::InvalidStateException, "invalid JoinMode");
187 }
188
189
190 bool ddd_JoinActive(const DDD::DDDContext& context)
191 {
192 return context.joinContext().joinMode != JoinMode::JMODE_IDLE;
193 }
194
195
196 bool JoinStepMode(DDD::DDDContext& context, JoinMode old)
197 {
198 auto& ctx = context.joinContext();
199 if (ctx.joinMode != old)
200 {
201 Dune::dwarn
202 << "wrong join-mode (currently in " << JoinModeName(ctx.joinMode)
203 << ", expected " << JoinModeName(old) << ")\n";
204 return false;
205 }
206
207 JoinSetMode(context, JoinSuccMode(ctx.joinMode));
208 return true;
209 }
210
211
212 /****************************************************************************/
213
214
215 void ddd_JoinInit(DDD::DDDContext& context)
216 {
217 auto& ctx = context.joinContext();
218
219 /* init control structures for JoinInfo-items in messages */
220 ctx.setJIJoin = reinterpret_cast<DDD::Join::JIJoinSet*>(New_JIJoinSet());
221 ctx.setJIAddCpl2 = reinterpret_cast<DDD::Join::JIAddCplSet*>(New_JIAddCplSet());
222 ctx.setJIAddCpl3 = reinterpret_cast<DDD::Join::JIAddCplSet*>(New_JIAddCplSet());
223
224 JoinSetMode(context, JoinMode::JMODE_IDLE);
225
226 ctx.phase1msg_t = LC_NewMsgType(context, "Join1Msg");
227 ctx.jointab_id = LC_NewMsgTable("GidTab",
228 ctx.phase1msg_t, sizeof(TEJoin));
229
230 ctx.phase2msg_t = LC_NewMsgType(context, "Join2Msg");
231 ctx.addtab_id = LC_NewMsgTable("AddCplTab",
232 ctx.phase2msg_t, sizeof(TEAddCpl));
233
234 ctx.phase3msg_t = LC_NewMsgType(context, "Join3Msg");
235 ctx.cpltab_id = LC_NewMsgTable("AddCplTab",
236 ctx.phase3msg_t, sizeof(TEAddCpl));
237 }
238
239
240 void ddd_JoinExit(DDD::DDDContext& context)
241 {
242 auto& ctx = context.joinContext();
243
244 JIJoinSet_Free(reinterpret_cast<JIJoinSet*>(ctx.setJIJoin));
245 JIAddCplSet_Free(reinterpret_cast<JIAddCplSet*>(ctx.setJIAddCpl2));
246 JIAddCplSet_Free(reinterpret_cast<JIAddCplSet*>(ctx.setJIAddCpl3));
247 }
248
249
250
251
252 END_UGDIM_NAMESPACE