00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "Numbering_dh.h"
00044 #include "Mat_dh.h"
00045 #include "Hash_i_dh.h"
00046 #include "Mem_dh.h"
00047 #include "shellSort_dh.h"
00048 #include "Parser_dh.h"
00049
00050
00051 #undef __FUNC__
00052 #define __FUNC__ "Numbering_dhCreate"
00053 void
00054 Numbering_dhCreate (Numbering_dh * numb)
00055 {
00056 START_FUNC_DH
00057 struct _numbering_dh *tmp =
00058 (struct _numbering_dh *) MALLOC_DH (sizeof (struct _numbering_dh));
00059 CHECK_V_ERROR;
00060 *numb = tmp;
00061
00062 tmp->size = 0;
00063 tmp->first = 0;
00064 tmp->m = 0;
00065 tmp->num_ext = 0;
00066 tmp->num_extLo = 0;
00067 tmp->num_extHi = 0;
00068 tmp->idx_ext = NULL;
00069 tmp->idx_extLo = NULL;
00070 tmp->idx_extHi = NULL;
00071 tmp->idx_ext = NULL;
00072 tmp->debug = Parser_dhHasSwitch (parser_dh, "-debug_Numbering");
00073 END_FUNC_DH}
00074
00075 #undef __FUNC__
00076 #define __FUNC__ "Numbering_dhDestroy"
00077 void
00078 Numbering_dhDestroy (Numbering_dh numb)
00079 {
00080 START_FUNC_DH if (numb->global_to_local != NULL)
00081 {
00082 Hash_i_dhDestroy (numb->global_to_local);
00083 CHECK_V_ERROR;
00084 }
00085 if (numb->idx_ext != NULL)
00086 {
00087 FREE_DH (numb->idx_ext);
00088 CHECK_V_ERROR;
00089 }
00090 FREE_DH (numb);
00091 CHECK_V_ERROR;
00092 END_FUNC_DH}
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 #undef __FUNC__
00103 #define __FUNC__ "Numbering_dhSetup"
00104 void
00105 Numbering_dhSetup (Numbering_dh numb, Mat_dh mat)
00106 {
00107 START_FUNC_DH int i, len, *cval = mat->cval;
00108 int num_ext, num_extLo, num_extHi;
00109 int m = mat->m, size;
00110 Hash_i_dh global_to_local_hash;
00111 int first = mat->beg_row, last = first + m;
00112 int *idx_ext;
00113 int data;
00114
00115
00116
00117
00118 numb->first = first;
00119 numb->m = m;
00120
00121
00122
00123
00124 numb->size = size = m;
00125 Hash_i_dhCreate (&(numb->global_to_local), m);
00126 CHECK_V_ERROR;
00127
00128 global_to_local_hash = numb->global_to_local;
00129 idx_ext = numb->idx_ext = (int *) MALLOC_DH (size * sizeof (int));
00130 CHECK_V_ERROR;
00131
00132
00133
00134
00135 len = mat->rp[m];
00136 num_ext = num_extLo = num_extHi = 0;
00137 for (i = 0; i < len; i++)
00138 {
00139 int index = cval[i];
00140
00141
00142 if (index < first || index >= last)
00143 {
00144
00145
00146 data = Hash_i_dhLookup (global_to_local_hash, cval[i]);
00147 CHECK_V_ERROR;
00148
00149 if (data == -1)
00150 {
00151
00152
00153
00154
00155
00156 if (m + num_ext >= size)
00157 {
00158 int newSize = size * 1.5;
00159 int *tmp = (int *) MALLOC_DH (newSize * sizeof (int));
00160 CHECK_V_ERROR;
00161 memcpy (tmp, idx_ext, size * sizeof (size));
00162 FREE_DH (idx_ext);
00163 CHECK_V_ERROR;
00164 size = numb->size = newSize;
00165 numb->idx_ext = idx_ext = tmp;
00166 SET_INFO ("reallocated ext_idx[]");
00167 }
00168
00169
00170 Hash_i_dhInsert (global_to_local_hash, index, num_ext);
00171 CHECK_V_ERROR;
00172 idx_ext[num_ext] = index;
00173
00174 num_ext++;
00175 if (index < first)
00176 {
00177 num_extLo++;
00178 }
00179 else
00180 {
00181 num_extHi++;
00182 }
00183 }
00184 }
00185 }
00186
00187 numb->num_ext = num_ext;
00188 numb->num_extLo = num_extLo;
00189 numb->num_extHi = num_extHi;
00190 numb->idx_extLo = idx_ext;
00191 numb->idx_extHi = idx_ext + num_extLo;
00192
00193
00194
00195
00196
00197 shellSort_int (num_ext, idx_ext);
00198
00199 Hash_i_dhReset (global_to_local_hash);
00200 CHECK_V_ERROR;
00201 for (i = 0; i < num_ext; i++)
00202 {
00203 Hash_i_dhInsert (global_to_local_hash, idx_ext[i], i + m);
00204 CHECK_V_ERROR;
00205 }
00206 END_FUNC_DH}
00207
00208 #undef __FUNC__
00209 #define __FUNC__ "Numbering_dhGlobalToLocal"
00210 void
00211 Numbering_dhGlobalToLocal (Numbering_dh numb, int len,
00212 int *global, int *local)
00213 {
00214 START_FUNC_DH int i;
00215 int first = numb->first;
00216 int last = first + numb->m;
00217 int data;
00218 Hash_i_dh global_to_local = numb->global_to_local;
00219
00220 for (i = 0; i < len; i++)
00221 {
00222 int idxGlobal = global[i];
00223 if (idxGlobal >= first && idxGlobal < last)
00224 {
00225 local[i] = idxGlobal - first;
00226
00227 }
00228 else
00229 {
00230 data = Hash_i_dhLookup (global_to_local, idxGlobal);
00231 CHECK_V_ERROR;
00232 if (data == -1)
00233 {
00234 sprintf (msgBuf_dh, "global index %i not found in map\n",
00235 idxGlobal);
00236 SET_V_ERROR (msgBuf_dh);
00237 }
00238 else
00239 {
00240 local[i] = data;
00241 }
00242 }
00243 }
00244 END_FUNC_DH}