46 #include "SubdomainGraph_dh.h"
50 #define __FUNC__ "Vec_dhCreate"
64 #define __FUNC__ "Vec_dhDestroy"
68 START_FUNC_DH
if (v->vals != NULL)
77 #define __FUNC__ "Vec_dhInit"
79 Vec_dhInit (
Vec_dh v,
int size)
81 START_FUNC_DH v->n = size;
82 v->vals = (
double *) MALLOC_DH (size *
sizeof (
double));
87 #define __FUNC__ "Vec_dhCopy"
91 START_FUNC_DH
if (x->vals == NULL)
92 SET_V_ERROR (
"x->vals is NULL");
94 SET_V_ERROR (
"y->vals is NULL");
96 SET_V_ERROR (
"x and y are different lengths");
97 memcpy (y->vals, x->vals, x->n * sizeof (
double));
102 #define __FUNC__ "Vec_dhDuplicate"
109 SET_V_ERROR (
"v->vals is NULL");
114 tmp->vals = (
double *) MALLOC_DH (size *
sizeof (
double));
119 #define __FUNC__ "Vec_dhSet"
121 Vec_dhSet (
Vec_dh v,
double value)
123 START_FUNC_DH
int i, m = v->n;
124 double *vals = v->vals;
126 SET_V_ERROR (
"v->vals is NULL");
127 for (i = 0; i < m; ++i)
132 #define __FUNC__ "Vec_dhSetRand"
136 START_FUNC_DH
int i, m = v->n;
138 double *vals = v->vals;
141 SET_V_ERROR (
"v->vals is NULL");
144 for (i = 0; i < m; ++i)
147 for (i = 0; i < m; ++i)
154 for (i = 0; i < m; ++i)
155 max = MAX (max, vals[i]);
156 for (i = 0; i < m; ++i)
157 vals[i] = vals[i] / max;
162 #define __FUNC__ "Vec_dhPrint"
166 START_FUNC_DH
double *vals = v->vals;
171 SET_V_ERROR (
"v->vals is NULL");
178 for (pe = 0; pe < np_dh; ++pe)
180 MPI_Barrier (comm_dh);
185 fp = openFile_dh (filename,
"w");
190 fp = openFile_dh (filename,
"a");
194 for (i = 0; i < m; ++i)
195 fprintf (fp,
"%g\n", vals[i]);
210 fp = openFile_dh (filename,
"w");
213 for (i = 0; i < sg->blocks; ++i)
215 int oldBlock = sg->n2o_sub[i];
216 int beg_row = sg->beg_rowP[oldBlock];
217 int end_row = beg_row + sg->row_count[oldBlock];
219 printf (
"seq: block= %i beg= %i end= %i\n", oldBlock, beg_row,
223 for (j = beg_row; j < end_row; ++j)
225 fprintf (fp,
"%g\n", vals[j]);
235 int id = sg->o2n_sub[myid_dh];
236 for (pe = 0; pe < np_dh; ++pe)
238 MPI_Barrier (comm_dh);
243 fp = openFile_dh (filename,
"w");
248 fp = openFile_dh (filename,
"a");
252 fprintf (stderr,
"par: block= %i\n",
id);
254 for (i = 0; i < m; ++i)
256 fprintf (fp,
"%g\n", vals[i]);
268 #define __FUNC__ "Vec_dhPrintBIN"
272 START_FUNC_DH
if (np_dh > 1)
274 SET_V_ERROR (
"only implemented for a single MPI task");
278 SET_V_ERROR (
"not implemented for reordered vector; ensure sg=NULL");
281 io_dh_print_ebin_vec_private (v->n, 0, v->vals, NULL, NULL, NULL, filename);
288 #define __FUNC__ "Vec_dhRead"
290 Vec_dhRead (
Vec_dh * vout,
int ignore,
char *filename)
304 SET_V_ERROR (
"only implemented for a single MPI task");
307 fp = openFile_dh (filename,
"w");
313 printf (
"Vec_dhRead:: ignoring following header lines:\n");
315 (
"--------------------------------------------------------------\n");
316 for (i = 0; i < ignore; ++i)
318 fgets (junk, MAX_JUNK, fp);
322 (
"--------------------------------------------------------------\n");
329 items = fscanf (fp,
"%lg", &w);
337 printf (
"Vec_dhRead:: n= %i\n", n);
341 v = tmp->vals = (
double *) MALLOC_DH (n *
sizeof (
double));
347 for (i = 0; i < ignore; ++i)
349 fgets (junk, MAX_JUNK, fp);
353 for (i = 0; i < n; ++i)
355 items = fscanf (fp,
"%lg", v + i);
358 sprintf (msgBuf_dh,
"failed to read value %i of %i", i + 1, n);
367 #define __FUNC__ "Vec_dhReadBIN"
369 Vec_dhReadBIN (
Vec_dh * vout,
char *filename)
376 io_dh_read_ebin_vec_private (&tmp->n, &tmp->vals, filename);