14 static int ReadArraySerial (
int,
int,
int*,
int*,
int,
void*,
void*,
double*,
double*,
char*,
int*);
16 static int ReadArrayParallel (
int,
int,
int*,
int*,
int,
void*,
void*,
double*,
double*,
char*,
int*);
17 static int ReadArrayMPI_IO (
int,
int,
int*,
int*,
int,
void*,
void*,
double*,
double*,
char*,
int*);
44 IERR ReadArraySerial(ndims,nvars,dim_global,dim_local,ghosts,s,m,x,u,fname_root,read_flag);
47 }
else if (!strcmp(solver->
input_mode,
"parallel")) {
48 ReadArrayParallel(ndims,nvars,dim_global,dim_local,ghosts,s,m,x,u,fname_root,read_flag);
50 }
else if (!strcmp(solver->
input_mode,
"mpi-io" )) {
51 ReadArrayMPI_IO(ndims,nvars,dim_global,dim_local,ghosts,s,m,x,u,fname_root,read_flag);
55 fprintf(stderr,
"Error: Illegal value (%s) for input_mode.\n",solver->
input_mode);
63 for (d = 0; d < ndims; d++) {
66 offset += (dim_local [d] + 2*ghosts);
70 for (d = 0; d < ndims; d++) {
71 double *X = &x[offset];
72 int *dim = dim_local, i;
73 if (mpi->
ip[d] == 0) {
75 for (i = 0; i < ghosts; i++) {
76 int delta = ghosts - i;
77 X[i] = X[ghosts] + ((double) delta) * (X[ghosts]-X[ghosts+1]);
80 if (mpi->
ip[d] == mpi->
iproc[d]-1) {
82 for (i = dim[d]+ghosts; i < dim[d]+2*ghosts; i++) {
83 int delta = i - (dim[d]+ghosts-1);
84 X[i] = X[dim[d]+ghosts-1]
85 + ((double) delta) * (X[dim[d]+ghosts-1]-X[dim[d]+ghosts-2]);
88 offset += (dim[d] + 2*ghosts);
166 int i, d, ferr, index[ndims];
167 double *ug = NULL, *xg = NULL;
176 strcpy(filename,fname_root);
177 strcat(filename,
".inp");
178 FILE *in; in = fopen(filename,
"r");
179 if (!in) *read_flag = 0;
183 printf(
"Reading array from ASCII file %s (Serial mode).\n",filename);
186 size = 1;
for (d=0; d<ndims; d++) size *= dim_global[d]; size *= nvars;
187 ug = (
double*) calloc(size,
sizeof(
double));
188 size = 0;
for (d=0; d<ndims; d++) size += dim_global[d];
189 xg = (
double*) calloc(size,
sizeof(
double));
193 for (d = 0; d < ndims; d++) {
194 for (i = 0; i < dim_global[d]; i++) {
195 ferr = fscanf(in,
"%lf",&xg[i+offset]);
197 printf(
"Error in ReadArraySerial(): unable to read data. ferr=%d\n", ferr);
201 offset += dim_global[d];
205 for (i = 0; i < nvars; i++) {
209 ferr = fscanf(in,
"%lf",&ug[p*nvars+i]);
211 printf(
"Error in ReadArraySerial(): unable to read data. ferr=%d\n", ferr);
223 strcpy(filename,fname_root);
224 strcat(filename,
".inp");
225 FILE *in; in = fopen(filename,
"rb");
226 if (!in) *read_flag = 0;
229 printf(
"Reading array from binary file %s (Serial mode).\n",filename);
233 size = 1;
for (d=0; d<ndims; d++) size *= dim_global[d]; size *= nvars;
234 ug = (
double*) calloc(size,
sizeof(
double));
235 size = 0;
for (d=0; d<ndims; d++) size += dim_global[d];
236 xg = (
double*) calloc(size,
sizeof(
double));
240 for (d = 0; d < ndims; d++) size += dim_global[d];
241 bytes = fread(xg,
sizeof(
double), size, in);
242 if ((
int)bytes != size) {
243 fprintf(stderr,
"Error in ReadArray(): Unable to read grid. Expected %d, Read %d.\n",
249 for (d = 0; d < ndims; d++) size *= dim_global[d]; size *= nvars;
250 bytes = fread(ug,
sizeof(
double), size, in);
251 if ((
int)bytes != size) {
252 fprintf(stderr,
"Error in ReadArray(): Unable to read solution. Expected %d, Read %d.\n",
269 dim_local,ghosts,nvars);
CHECKERR(ierr);
273 int offset_global = 0, offset_local = 0;
274 for (d=0; d<ndims; d++) {
276 &x[offset_local+ghosts],
278 offset_global += dim_global[d];
279 offset_local += dim_local [d] + 2*ghosts;
362 strcpy(filename_root,fname_root);
363 strcat(filename_root,
"_par.inp");
370 in = fopen(filename,
"rb");
371 if (!in) *read_flag = 0;
381 if (!mpi->
rank) printf(
"Reading from binary file %s.xxx (parallel mode).\n",filename_root);
384 int sizex = 0;
for (d=0; d<ndims; d++) sizex += dim_local[d];
385 int sizeu = nvars;
for (d=0; d<ndims; d++) sizeu *= dim_local[d];
388 double *buffer = (
double*) calloc (sizex+sizeu,
sizeof(
double));
393 double *read_buffer = NULL;
394 int read_size_x, read_size_u, read_total_size;
395 int is[ndims], ie[ndims];
403 in = fopen(filename,
"rb");
405 fprintf(stderr,
"Error in ReadArrayParallel(): File %s could not be opened.\n",filename);
410 bytes = fread(buffer,
sizeof(
double),(sizex+sizeu),in);
411 if (bytes != (sizex+sizeu)) {
412 fprintf(stderr,
"Error in ReadArrayParallel(): File %s contains insufficient data.\n",filename);
417 for (proc=mpi->
GroupStartRank+1; proc<mpi->GroupEndRank; proc++) {
421 read_size_x = 0;
for (d=0; d<ndims; d++) read_size_x += (ie[d]-is[d]);
422 read_size_u = nvars;
for (d=0; d<ndims; d++) read_size_u *= (ie[d]-is[d]);
423 read_total_size = read_size_x + read_size_u;
424 read_buffer = (
double*) calloc (read_total_size,
sizeof(
double));
426 bytes = fread(read_buffer,
sizeof(
double),read_total_size,in);
427 if (bytes != read_total_size) {
428 fprintf(stderr,
"Error in ReadArrayParallel(): File %s contains insufficient data.\n",filename);
432 MPI_Request req = MPI_REQUEST_NULL;
433 MPI_Isend(read_buffer,read_total_size,MPI_DOUBLE,proc,1100,mpi->
world,&req);
434 MPI_Wait(&req,MPI_STATUS_IGNORE);
445 MPI_Request req = MPI_REQUEST_NULL;
446 MPI_Irecv(buffer,(sizex+sizeu),MPI_DOUBLE,mpi->
IORank,1100,mpi->
world,&req);
447 MPI_Wait(&req,MPI_STATUS_IGNORE);
453 int offset1 = 0, offset2 = 0;
454 for (d = 0; d < ndims; d++) {
455 _ArrayCopy1D_((buffer+offset2),(x+offset1+ghosts),dim_local[d]);
456 offset1 += (dim_local[d]+2*ghosts);
457 offset2 += dim_local[d];
463 IERR ArrayCopynD(ndims,(buffer+sizex),u,dim_local,0,ghosts,index,nvars);
534 strcpy(filename,fname_root);
535 strcat(filename,
"_mpi.inp");
540 in = fopen(filename,
"rb");
541 if (!in) *read_flag = 0;
551 if (!mpi->
rank) printf(
"Reading from binary file %s (MPI-IO mode).\n",filename);
554 int sizex = 0;
for (d=0; d<ndims; d++) sizex += dim_local[d];
555 int sizeu = nvars;
for (d=0; d<ndims; d++) sizeu *= dim_local[d];
558 double *buffer = (
double*) calloc (sizex+sizeu,
sizeof(
double));
563 double *read_buffer = NULL;
564 int read_size_x, read_size_u, read_total_size;
565 int is[ndims], ie[ndims], size;
568 long long offset = 0;
569 for (proc=0; proc < mpi->
rank; proc++) {
573 size = 0;
for (d=0; d<ndims; d++) size += (ie[d]-is[d]);
576 size = nvars;
for (d=0; d<ndims; d++) size *= (ie[d]-is[d]);
584 error = MPI_File_open(mpi->
IOWorld,filename,MPI_MODE_RDONLY,MPI_INFO_NULL,&in);
585 if (error != MPI_SUCCESS) {
586 fprintf(stderr,
"Error in ReadArrayMPI_IO(): Unable to open %s.\n",filename);
591 MPI_Offset FileOffset = (MPI_Offset) (offset *
sizeof(
double));
592 MPI_File_seek(in,FileOffset,MPI_SEEK_SET);
595 MPI_File_read(in,buffer,(sizex+sizeu)*
sizeof(
double),MPI_BYTE,&status);
598 for (proc=mpi->
GroupStartRank+1; proc<mpi->GroupEndRank; proc++) {
602 read_size_x = 0;
for (d=0; d<ndims; d++) read_size_x += (ie[d]-is[d]);
603 read_size_u = nvars;
for (d=0; d<ndims; d++) read_size_u *= (ie[d]-is[d]);
604 read_total_size = read_size_x + read_size_u;
605 read_buffer = (
double*) calloc (read_total_size,
sizeof(
double));
607 MPI_File_read(in,read_buffer,read_total_size*
sizeof(
double),MPI_BYTE,&status);
609 MPI_Request req = MPI_REQUEST_NULL;
610 MPI_Isend(read_buffer,read_total_size,MPI_DOUBLE,proc,1100,mpi->
world,&req);
611 MPI_Wait(&req,MPI_STATUS_IGNORE);
622 MPI_Request req = MPI_REQUEST_NULL;
623 MPI_Irecv(buffer,(sizex+sizeu),MPI_DOUBLE,mpi->
IORank,1100,mpi->
world,&req);
624 MPI_Wait(&req,MPI_STATUS_IGNORE);
630 int offset1 = 0, offset2 = 0;
631 for (d = 0; d < ndims; d++) {
632 _ArrayCopy1D_((buffer+offset2),(x+offset1+ghosts),dim_local[d]);
633 offset1 += (dim_local[d]+2*ghosts);
634 offset2 += dim_local[d];
640 IERR ArrayCopynD(ndims,(buffer+sizex),u,dim_local,0,ghosts,index,nvars);
MPI related function definitions.
int MPIMin_integer(int *, int *, int, void *)
int MPIPartitionArray1D(void *, double *, double *, int, int, int, int)
int MPIBroadcast_integer(int *, int, int, void *)
char ip_file_type[_MAX_STRING_SIZE_]
Some basic definitions and macros.
int MPIPartitionArraynD(int, void *, double *, double *, int *, int *, int, int)
char input_mode[_MAX_STRING_SIZE_]
int MPIExchangeBoundaries1D(void *, double *, int, int, int, int)
Structure containing all solver-specific variables and functions.
#define _MAX_STRING_SIZE_
void MPIGetFilename(char *, void *, char *)
Contains structure definition for hypar.
#define _ArrayIndex1D_(N, imax, i, ghost, index)
INLINE int ArrayCopynD(int, const double *, double *, int *, int, int, int *, int)
#define _ArraySetValue_(x, size, value)
static int ReadArrayMPI_IO(int, int, int *, int *, int, void *, void *, double *, double *, char *, int *)
#define _ArrayIncrementIndex_(N, imax, i, done)
int MPILocalDomainLimits(int, int, void *, int *, int *, int *)
Structure of MPI-related variables.
int ReadArray(int ndims, int nvars, int *dim_global, int *dim_local, int ghosts, void *s, void *m, double *x, double *u, char *fname_root, int *read_flag)
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
static int ReadArraySerial(int, int, int *, int *, int, void *, void *, double *, double *, char *, int *)
static int ReadArrayParallel(int, int, int *, int *, int, void *, void *, double *, double *, char *, int *)