43 #include "SortedList_dh.h"
45 #include "Parser_dh.h"
46 #include "Hash_i_dh.h"
47 #include "SubdomainGraph_dh.h"
77 #define __FUNC__ "SortedList_dhCreate"
91 tmp->o2n_external = NULL;
92 tmp->o2n_local = NULL;
98 tmp->debug = Parser_dhHasSwitch (parser_dh,
"-debug_SortedList");
103 #define __FUNC__ "SortedList_dhDestroy"
107 START_FUNC_DH
if (sList->list != NULL)
109 FREE_DH (sList->list);
118 #define __FUNC__ "SortedList_dhInit"
122 START_FUNC_DH sList->o2n_local = sg->o2n_col;
124 sList->beg_row = sg->beg_row[myid_dh];
125 sList->beg_rowP = sg->beg_rowP[myid_dh];
128 sList->o2n_external = sg->o2n_ext;
131 sList->alloc = sList->m + 5;
132 sList->list = (
SRecord *) MALLOC_DH (sList->alloc * sizeof (
SRecord));
133 sList->list[0].col = INT_MAX;
134 sList->list[0].next = 0;
139 #define __FUNC__ "SortedList_dhReset"
143 START_FUNC_DH sList->row = row;
148 sList->list[0].next = 0;
153 #define __FUNC__ "SortedList_dhReadCount"
157 START_FUNC_DH END_FUNC_VAL (sList->count - 1)}
160 #define __FUNC__ "SortedList_dhResetGetSmallest"
164 START_FUNC_DH sList->getLower = 0;
169 #define __FUNC__ "SortedList_dhGetSmallest"
173 START_FUNC_DH
SRecord * node = NULL;
175 int get = sList->get;
177 get = list[
get].next;
179 if (list[
get].col < INT_MAX)
187 #define __FUNC__ "SortedList_dhGetSmallestLowerTri"
191 START_FUNC_DH
SRecord * node = NULL;
193 int getLower = sList->getLower;
194 int globalRow = sList->row + sList->beg_rowP;
196 getLower = list[getLower].next;
198 if (list[getLower].col < globalRow)
200 node = &(list[getLower]);
201 sList->getLower = getLower;
207 #define __FUNC__ "SortedList_dhPermuteAndInsert"
212 START_FUNC_DH
bool wasInserted =
false;
214 double testVal = fabs (sr->val);
215 int beg_row = sList->beg_row, end_row = beg_row + sList->m;
216 int beg_rowP = sList->beg_rowP;
219 if (col >= beg_row && col < end_row)
223 col = sList->o2n_local[col];
226 if (testVal > thresh || col == sList->row)
245 if (testVal < thresh)
246 goto END_OF_FUNCTION;
249 if (sList->o2n_external == NULL)
255 int tmp = Hash_i_dhLookup (sList->o2n_external, col);
271 SortedList_dhInsert (sList, sr);
278 END_FUNC_VAL (wasInserted)}
282 #define __FUNC__ "SortedList_dhInsertOrUpdate"
286 START_FUNC_DH
SRecord * node = SortedList_dhFind (sList, sr);
291 SortedList_dhInsert (sList, sr);
296 node->level = MIN (sr->level, node->level);
303 #define __FUNC__ "SortedList_dhInsert"
307 START_FUNC_DH
int prev, next;
308 int ct, col = sr->col;
312 if (sList->countMax == sList->alloc)
314 lengthen_list_private (sList);
320 ct = sList->countMax;
321 sList->countMax += 1;
325 list[ct].level = sr->level;
326 list[ct].val = sr->val;
331 while (col > list[next].col)
334 next = list[next].next;
336 list[prev].next = ct;
337 list[ct].next = next;
342 #define __FUNC__ "SortedList_dhFind"
346 START_FUNC_DH
int i, count = sList->countMax;
352 for (i = 1; i < count; ++i)
365 #define __FUNC__ "lengthen_list_private"
369 START_FUNC_DH
SRecord * tmp = sList->list;
370 int size = sList->alloc = 2 * sList->alloc;
372 SET_INFO (
"lengthening list");
375 memcpy (sList->list, tmp, sList->countMax * sizeof (
SRecord));
376 SET_INFO (
"doubling size of sList->list");
388 int thisSubdomain,
int col);
392 #define __FUNC__ "SortedList_dhEnforceConstraint"
396 START_FUNC_DH
int thisSubdomain = myid_dh;
398 int beg_rowP = sList->beg_rowP;
399 int end_rowP = beg_rowP + sList->m;
402 if (Parser_dhHasSwitch (parser_dh,
"-debug_SortedList"))
407 fprintf (logFile,
"SLIST ======= enforcing constraint for row= %i\n",
410 fprintf (logFile,
"\nSLIST ---- before checking: ");
411 count = SortedList_dhReadCount (sList);
415 SRecord *sr = SortedList_dhGetSmallest (sList);
417 fprintf (logFile,
"%i ", sr->col + 1);
419 fprintf (logFile,
"\n");
424 count = SortedList_dhReadCount (sList);
429 SRecord *sr = SortedList_dhGetSmallest (sList);
435 fprintf (logFile,
"SLIST next col= %i\n", col + 1);
440 if (col < beg_rowP || col >= end_rowP)
445 fprintf (logFile,
"SLIST external col: %i ; ", 1 + col);
451 if (check_constraint_private (sg, thisSubdomain, col))
453 delete_private (sList, col);
459 fprintf (logFile,
" deleted\n");
466 fprintf (logFile,
" kept\n");
475 fprintf (logFile,
"SLIST---- after checking: ");
476 count = SortedList_dhReadCount (sList);
480 SRecord *sr = SortedList_dhGetSmallest (sList);
482 fprintf (logFile,
"%i ", sr->col + 1);
484 fprintf (logFile,
"\n");
494 #define __FUNC__ "check_constraint_private"
498 START_FUNC_DH
bool retval =
false;
502 p2 = SubdomainGraph_dhFindOwner (sg, j,
true);
504 nabors = sg->adj + sg->ptrs[p1];
505 count = sg->ptrs[p1 + 1] - sg->ptrs[p1];
507 for (i = 0; i < count; ++i)
516 END_FUNC_VAL (!retval)}
519 #define __FUNC__ "delete_private"
523 START_FUNC_DH
int curNode = 0;
530 while (list[list[curNode].next].col != col)
532 curNode = list[curNode].next;
536 next = list[curNode].next;
540 next = list[next].next;
541 list[curNode].next = next;