1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 /****************************************************************************/
4 /*                                                                          */
5 /* File:      ifcheck.c                                                     */
6 /*                                                                          */
7 /* Purpose:   routines concerning interfaces between processors             */
8 /*            checking routines                                             */
9 /*                                                                          */
10 /* Author:    Klaus Birken                                                  */
11 /*            Institut fuer Computeranwendungen III                         */
12 /*            Universitaet Stuttgart                                        */
13 /*            Pfaffenwaldring 27                                            */
14 /*            70550 Stuttgart                                               */
15 /*            email: birken@ica3.uni-stuttgart.de                           */
16 /*                                                                          */
17 /* History:   960926 kb  begin                                              */
18 /*                                                                          */
19 /* Remarks:                                                                 */
20 /*                                                                          */
21 /****************************************************************************/
22 
23 /****************************************************************************/
24 /*                                                                          */
25 /* include files                                                            */
26 /*            system include files                                          */
27 /*            application include files                                     */
28 /*                                                                          */
29 /****************************************************************************/
30 
31 /* standard C library */
32 #include <config.h>
33 #include <cstdlib>
34 #include <cstdio>
35 
36 #include <iomanip>
37 
38 #include <dune/common/stdstreams.hh>
39 
40 #include <dune/uggrid/parallel/ddd/dddi.h>
41 #include <dune/uggrid/parallel/ddd/basic/notify.h>
42 #include "if.h"
43 
44 using namespace PPIF;
45 
46 /* general error string */
47 #define ERRSTR "    DDD-IFC Warning: "
48 
49 START_UGDIM_NAMESPACE
50 
51 /****************************************************************************/
52 /*                                                                          */
53 /* definition of static variables                                           */
54 /*                                                                          */
55 /****************************************************************************/
56 
57 
58 
59 
60 /****************************************************************************/
61 /*                                                                          */
62 /* routines                                                                 */
63 /*                                                                          */
64 /****************************************************************************/
65 
66 
67 
DDD_CheckInterface(DDD::DDDContext & context,DDD_IF ifId)68 static int DDD_CheckInterface(DDD::DDDContext& context, DDD_IF ifId)
69 {
70   using std::setw;
71 
72   auto& theIF = context.ifCreateContext().theIf;
73   const auto& me = context.me();
74 
75   int errors=0;
76   IF_PROC *h;
77   NOTIFY_DESC *msgs = DDD_NotifyBegin(context, theIF[ifId].nIfHeads);
78   int nRecvs, k;
79 
80   /* fill NOTIFY_DESCS */
81   k=0;
82   ForIF(context, ifId, h)
83   {
84     msgs[k].proc = h->proc;
85     msgs[k].size = h->nItems;
86     k++;
87   }
88 
89   nRecvs = DDD_Notify(context);
90   if (nRecvs==ERROR)
91   {
92     Dune::dwarn << "Notify failed on proc " << me << "\n";
93     errors++;
94   }
95   else
96   {
97     if (nRecvs!=theIF[ifId].nIfHeads)
98     {
99       Dune::dwarn
100         << ERRSTR "IF " << setw(2) << ifId << "not symmetric on proc "
101         << me << " (" << nRecvs << " != " << theIF[ifId].nIfHeads << ")\n";
102       errors++;
103     }
104 
105     ForIF(context, ifId, h)
106     {
107       for(k=0; k<nRecvs; k++)
108       {
109         if (msgs[k].proc==h->proc)
110         {
111           if (msgs[k].size!=h->nItems)
112           {
113             Dune::dwarn
114               << ERRSTR "IF " << setw(2) << ifId << " proc " << me << "->"
115               << msgs[k].proc << " has non-symmetric items (" << h->nItems
116               << " != " << msgs[k].size << ")\n";
117             errors++;
118           }
119         }
120       }
121     }
122   }
123 
124   DDD_NotifyEnd(context);
125   return(errors);
126 }
127 
128 
129 /****************************************************************************/
130 
131 
DDD_CheckInterfaces(DDD::DDDContext & context)132 int DDD_CheckInterfaces(DDD::DDDContext& context)
133 {
134   const auto& nIFs = context.ifCreateContext().nIfs;
135 
136   int errors = 0;
137   for(int i = 0; i < nIFs; ++i)
138   {
139     errors += DDD_CheckInterface(context, i);
140   }
141 
142   return(errors);
143 }
144 
145 /****************************************************************************/
146 
147 END_UGDIM_NAMESPACE
148