/[escript]/trunk/paso/src/IndexList.c
ViewVC logotype

Contents of /trunk/paso/src/IndexList.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3283 - (show annotations)
Mon Oct 18 22:39:28 2010 UTC (8 years, 11 months ago) by gross
File MIME type: text/plain
File size: 3591 byte(s)
AMG reengineered, BUG is Smoother fixed.


1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15
16 /**************************************************************/
17
18 /* Paso: Index List */
19
20 /**************************************************************/
21
22 /* Author: Lutz Gross, l.gross@uq.edu.au */
23
24 /**************************************************************/
25
26 #include "IndexList.h"
27 #include "Paso.h"
28
29 /* inserts row index row into the Paso_IndexList in if it does not exist */
30
31 void Paso_IndexList_insertIndex(Paso_IndexList* in, index_t index) {
32 dim_t i;
33 /* is index in in? */
34 for (i=0;i<in->n;i++) {
35 if (in->index[i]==index) return;
36 }
37 /* index could not be found */
38 if (in->n==INDEXLIST_LENGTH) {
39 /* if in->index is full check the extension */
40 if (in->extension==NULL) {
41 in->extension=TMPMEMALLOC(1,Paso_IndexList);
42 if (Esys_checkPtr(in->extension)) return;
43 in->extension->n=0;
44 in->extension->extension=NULL;
45 }
46 Paso_IndexList_insertIndex(in->extension,index);
47 } else {
48 /* insert index into in->index*/
49 in->index[in->n]=index;
50 in->n++;
51 }
52 }
53
54 /* counts the number of row indices in the Paso_IndexList in */
55
56 dim_t Paso_IndexList_count(Paso_IndexList* in, index_t range_min,index_t range_max) {
57 dim_t i;
58 dim_t out=0;
59 register index_t itmp;
60 if (in==NULL) {
61 return 0;
62 } else {
63 for (i=0;i<in->n;i++) {
64 itmp=in->index[i];
65 if ((itmp>=range_min) && (range_max>itmp)) ++out;
66 }
67 return out+Paso_IndexList_count(in->extension, range_min,range_max);
68 }
69 }
70
71 /* count the number of row indices in the Paso_IndexList in */
72
73 void Paso_IndexList_toArray(Paso_IndexList* in, index_t* array, index_t range_min,index_t range_max, index_t index_offset) {
74 dim_t i, ptr;
75 register index_t itmp;
76 if (in!=NULL) {
77 ptr=0;
78 for (i=0;i<in->n;i++) {
79 itmp=in->index[i];
80 if ((itmp>=range_min) && (range_max>itmp)) {
81 array[ptr]=itmp+index_offset;
82 ptr++;
83 }
84
85 }
86 Paso_IndexList_toArray(in->extension,&(array[ptr]), range_min, range_max, index_offset);
87 }
88 }
89
90 /* deallocates the Paso_IndexList in by recursive calls */
91
92 void Paso_IndexList_free(Paso_IndexList* in) {
93 if (in!=NULL) {
94 Paso_IndexList_free(in->extension);
95 TMPMEMFREE(in);
96 }
97 }
98
99 Paso_IndexListArray* Paso_IndexListArray_alloc(const dim_t n)
100 {
101 register dim_t i;
102 Paso_IndexListArray* out = MEMALLOC(1, Paso_IndexListArray);
103
104 if (! Esys_checkPtr(out)) {
105
106 out->n=n;
107 out->index_list=TMPMEMALLOC(out->n,Paso_IndexList);
108
109 if (Esys_checkPtr(out->index_list)) {
110 Paso_IndexListArray_free(out);
111 } else {
112 #pragma omp parallel for private(i) schedule(static)
113 for(i=0; i<out->n; ++i) {
114 out->index_list[i].extension=NULL;
115 out->index_list[i].n=0;
116 }
117 }
118
119 }
120 return out;
121 }
122
123 void Paso_IndexListArray_free(Paso_IndexListArray* in)
124 {
125 register dim_t i;
126 if (in !=NULL) {
127
128 if (in->index_list!=NULL) {
129 #pragma omp parallel for private(i) schedule(static)
130 for(i=0; i<in->n; ++i) Paso_IndexList_free(in->index_list[i].extension);
131
132 MEMFREE(in->index_list);
133 }
134 MEMFREE(in);
135
136 }
137
138 }

  ViewVC Help
Powered by ViewVC 1.1.26