work on H5Block examples
This commit is contained in:
@@ -16,19 +16,19 @@ noinst_PROGRAMS =
|
||||
if ENABLE_C
|
||||
noinst_PROGRAMS += \
|
||||
fields \
|
||||
read_write
|
||||
read_write_scalar_field
|
||||
endif
|
||||
|
||||
if ENABLE_FORTRAN
|
||||
noinst_PROGRAMS += H5BlockExampleF
|
||||
noinst_PROGRAMS += read_write_scalar_fieldf
|
||||
endif
|
||||
|
||||
fields_SOURCES = fields.c
|
||||
read_write_SOURCES = read_write.c
|
||||
H5BlockExampleF_SOURCES = H5BlockExampleF.f90
|
||||
read_write_scalar_field_SOURCES = read_write_scalar_field.c
|
||||
read_write_scalar_fieldf_SOURCES = read_write_scalar_fieldf.f90
|
||||
|
||||
%.o : %.f90
|
||||
$(FC) $(FFLAGS) -c $<
|
||||
|
||||
distclean-local:
|
||||
clean-local:
|
||||
$(RM) *~
|
||||
|
||||
+22
-17
@@ -1,38 +1,43 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <mpi.h>
|
||||
|
||||
#include <H5.h>
|
||||
#include <H5Block.h>
|
||||
|
||||
#define XSIZE 8
|
||||
#define YSIZE 8
|
||||
#define ZSIZE 8
|
||||
#define DATASIZE XSIZE*YSIZE*ZSIZE
|
||||
#define XSIZE 8
|
||||
#define YSIZE 8
|
||||
#define ZSIZE 8
|
||||
#define DATASIZE XSIZE*YSIZE*ZSIZE
|
||||
|
||||
#define VERBOSITY H5_VERBOSE_DEFAULT
|
||||
#define FNAME "example_fields.h5"
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char** argv
|
||||
) {
|
||||
int rank, nprocs;
|
||||
h5_int64_t verbosity = VERBOSITY;
|
||||
|
||||
h5_float64_t ex[DATASIZE];
|
||||
h5_float64_t ey[DATASIZE];
|
||||
h5_float64_t ez[DATASIZE];
|
||||
h5_float64_t q[DATASIZE];
|
||||
h5_file_t file;
|
||||
|
||||
// initialize MPI
|
||||
// initialize MPI & H5hut
|
||||
int comm_rank = 0;
|
||||
int comm_size = 1;
|
||||
MPI_Init (&argc, &argv);
|
||||
MPI_Comm_rank (MPI_COMM_WORLD, &rank);
|
||||
MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
|
||||
MPI_Comm comm = MPI_COMM_WORLD;
|
||||
MPI_Comm_rank (comm, &comm_rank);
|
||||
MPI_Comm_size (comm, &comm_size);
|
||||
|
||||
H5SetVerbosityLevel(H5_VERBOSE_INFO);
|
||||
H5AbortOnError ();
|
||||
H5SetVerbosityLevel (verbosity);
|
||||
|
||||
// open file and go to step#0
|
||||
h5_file_t file = H5OpenFile (FNAME, H5_O_RDONLY, H5_PROP_DEFAULT);
|
||||
H5SetStep (file, 0);
|
||||
|
||||
file = H5OpenFile ("fields.h5", H5_O_WRONLY, MPI_COMM_WORLD);
|
||||
H5SetStep(file, 0);
|
||||
H5Block3dSetView (file,
|
||||
rank*XSIZE, (rank+1)*XSIZE - 1,
|
||||
comm_rank*XSIZE, (comm_rank+1)*XSIZE - 1,
|
||||
0, YSIZE - 1,
|
||||
0, ZSIZE - 1);
|
||||
H5Block3dWriteScalarFieldFloat64(file, "Q", q);
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
/*
|
||||
Copyright (c) 2006-2014, The Regents of the University of California,
|
||||
through Lawrence Berkeley National Laboratory (subject to receipt of any
|
||||
required approvals from the U.S. Dept. of Energy) and the Paul Scherrer
|
||||
Institut (Switzerland). All rights reserved.
|
||||
|
||||
License: see file COPYING in top level of source distribution.
|
||||
*/
|
||||
|
||||
#include <hdf5.h>
|
||||
#include "H5hut.h"
|
||||
|
||||
#define NPROCS 8
|
||||
#define DEFAULT_VERBOSITY H5_VERBOSE_DEFAULT
|
||||
|
||||
struct H5BlockPartition {
|
||||
h5_int64_t i_start;
|
||||
@@ -262,34 +267,17 @@ _write_file (
|
||||
MPI_Comm comm,
|
||||
struct H5BlockPartition *layout
|
||||
) {
|
||||
|
||||
h5_file_t f;
|
||||
h5_int64_t timestep = 0;
|
||||
h5_int64_t herr;
|
||||
|
||||
printf ("PROC[%d]: Open file \"%s\" for writing ...\n",
|
||||
printf ("PROC[%d]: Open file \"%s\" for writing ...\n",
|
||||
myproc, fname );
|
||||
|
||||
f = H5OpenFile ( fname, H5_O_WRONLY, comm );
|
||||
if ( f == H5_FAILURE ) return -1;
|
||||
h5_file_t file = H5OpenFile (fname, H5_O_WRONLY, H5_PROP_DEFAULT);
|
||||
H5SetStep (file, 0);
|
||||
|
||||
herr = H5SetStep ( f, timestep );
|
||||
if ( herr < 0 ) return herr;
|
||||
_write_data (file, myproc, layout);
|
||||
_write_attributes (file, myproc);
|
||||
|
||||
if ( _write_data ( f, myproc, layout ) < 0 ) {
|
||||
printf ("Failed to write file \"%s\"\n", fname );
|
||||
return 2;
|
||||
}
|
||||
|
||||
if ( _write_attributes ( f, myproc ) < 0 ) {
|
||||
printf ("Failed to write attributes \"%s\"\n", fname );
|
||||
return 2;
|
||||
}
|
||||
H5CloseFile (file);
|
||||
|
||||
herr = H5CloseFile (f);
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
return 0;
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
static h5_int64_t
|
||||
@@ -300,29 +288,25 @@ _read_data (
|
||||
) {
|
||||
|
||||
h5_int64_t i, j, k, idx;
|
||||
h5_int64_t herr;
|
||||
h5_float64_t *data;
|
||||
h5_int64_t i_dims = layout->i_end - layout->i_start + 1;
|
||||
h5_int64_t j_dims = layout->j_end - layout->j_start + 1;
|
||||
h5_int64_t k_dims = layout->k_end - layout->k_start + 1;
|
||||
|
||||
printf ( "Reading Step #%lld\n", (long long)H5GetStep (f) );
|
||||
printf ("Reading Step #%lld\n", (long long)H5GetStep (f));
|
||||
|
||||
data = malloc ( i_dims * j_dims * k_dims * sizeof ( *data ) );
|
||||
data = malloc (i_dims * j_dims * k_dims * sizeof (*data));
|
||||
|
||||
herr = H5Block3dSetView (
|
||||
H5Block3dSetView (
|
||||
f,
|
||||
layout->i_start, layout->i_end,
|
||||
layout->j_start, layout->j_end,
|
||||
layout->k_start, layout->k_end );
|
||||
if ( herr < 0 ) return herr;
|
||||
H5Block3dReadScalarFieldFloat64 ( f, "TestField", data );
|
||||
|
||||
herr = H5Block3dReadScalarFieldFloat64 ( f, "TestField", data );
|
||||
if ( herr < 0 ) return herr;
|
||||
|
||||
for ( i = 0; i < i_dims; i++ ) {
|
||||
for ( j = 0; j < j_dims; j++ ) {
|
||||
for ( k = 0; k < k_dims; k++ ) {
|
||||
for (i = 0; i < i_dims; i++) {
|
||||
for (j = 0; j < j_dims; j++) {
|
||||
for (k = 0; k < k_dims; k++) {
|
||||
idx = _calc_index (
|
||||
i, i_dims,
|
||||
j, j_dims,
|
||||
@@ -332,7 +316,7 @@ _read_data (
|
||||
+ 1000 * j
|
||||
+ 100000 * i
|
||||
+ 10000000 * myproc;
|
||||
if ( *(data + idx) != value ) {
|
||||
if (*(data + idx) != value) {
|
||||
printf (
|
||||
"PROC[%d]: "
|
||||
"value missmatch for (%lld,%lld,%lld); is: %f;"
|
||||
@@ -346,9 +330,9 @@ _read_data (
|
||||
}
|
||||
}
|
||||
|
||||
free ( data );
|
||||
free (data);
|
||||
|
||||
return 0;
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
static h5_int64_t
|
||||
@@ -359,45 +343,41 @@ _read_attributes (
|
||||
) {
|
||||
h5_int64_t timestep = 0;
|
||||
|
||||
h5_int64_t herr = H5SetStep ( f, timestep );
|
||||
if ( herr < 0 ) return herr;
|
||||
H5SetStep (f, timestep);
|
||||
|
||||
char sval[16];
|
||||
herr = H5BlockReadFieldAttribString (
|
||||
H5BlockReadFieldAttribString (
|
||||
f,
|
||||
"TestField",
|
||||
"TestString",
|
||||
sval );
|
||||
if ( herr < 0 ) return -1;
|
||||
if ( strcmp ( sval, "42" ) != 0 ) {
|
||||
printf ( "Error reading string attribute: "
|
||||
"Value is \"%s\" and should be \"42\"\n", sval );
|
||||
if (strcmp (sval, "42") != 0) {
|
||||
printf ("Error reading string attribute: "
|
||||
"Value is \"%s\" and should be \"42\"\n", sval);
|
||||
}
|
||||
|
||||
h5_int64_t ival[1];
|
||||
h5_float64_t rval[1];
|
||||
herr = H5BlockReadFieldAttribInt64 (
|
||||
H5BlockReadFieldAttribInt64 (
|
||||
f,
|
||||
"TestField",
|
||||
"TestInt64",
|
||||
ival );
|
||||
if ( herr < 0 ) return -1;
|
||||
if ( ival[0] != 42 ) {
|
||||
printf ( "Error reading int64 attribute: "
|
||||
"Value is %lld and should be 42\n",
|
||||
(long long) ival[0] );
|
||||
if (ival[0] != 42) {
|
||||
printf ("Error reading int64 attribute: "
|
||||
"Value is %lld and should be 42\n",
|
||||
(long long) ival[0]);
|
||||
}
|
||||
|
||||
herr = H5BlockReadFieldAttribFloat64 (
|
||||
H5BlockReadFieldAttribFloat64 (
|
||||
f,
|
||||
"TestField",
|
||||
"TestFloat64",
|
||||
rval );
|
||||
if ( herr < 0 ) return -1;
|
||||
if ( rval[0] != 42.0 ) {
|
||||
printf ( "Error reading float64 attribute: "
|
||||
"Value is %f and should be 42.0\n",
|
||||
rval[0] );
|
||||
if (rval[0] != 42.0) {
|
||||
printf ("Error reading float64 attribute: "
|
||||
"Value is %f and should be 42.0\n",
|
||||
rval[0]);
|
||||
}
|
||||
|
||||
h5_float64_t x_origin;
|
||||
@@ -407,31 +387,29 @@ _read_attributes (
|
||||
h5_float64_t y_spacing;
|
||||
h5_float64_t z_spacing;
|
||||
|
||||
herr = H5Block3dGetFieldOrigin (
|
||||
H5Block3dGetFieldOrigin (
|
||||
f, "TestField",
|
||||
&x_origin,
|
||||
&y_origin,
|
||||
&z_origin );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
if ( x_origin != 1.0 || y_origin != 2.0 || z_origin != 3.0 ) {
|
||||
if (x_origin != 1.0 || y_origin != 2.0 || z_origin != 3.0) {
|
||||
printf (
|
||||
"Error reading field origin: Read values (%f,%f,%f)\n",
|
||||
x_origin, y_origin, z_origin );
|
||||
x_origin, y_origin, z_origin);
|
||||
}
|
||||
herr = H5Block3dGetFieldSpacing (
|
||||
H5Block3dGetFieldSpacing (
|
||||
f, "TestField",
|
||||
&x_spacing,
|
||||
&y_spacing,
|
||||
&z_spacing );
|
||||
if ( herr < 0 ) return -1;
|
||||
if ( x_spacing != 2.0 || y_spacing != 3.0 || z_spacing != 4.0 ) {
|
||||
if (x_spacing != 2.0 || y_spacing != 3.0 || z_spacing != 4.0) {
|
||||
printf (
|
||||
"Error reading field spacing: Read values (%f,%f,%f)\n",
|
||||
x_spacing, y_spacing, z_spacing );
|
||||
x_spacing, y_spacing, z_spacing);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
static h5_int64_t
|
||||
@@ -441,33 +419,18 @@ _read_file (
|
||||
MPI_Comm comm,
|
||||
struct H5BlockPartition *layout
|
||||
) {
|
||||
|
||||
h5_file_t f;
|
||||
h5_int64_t timestep = 0;
|
||||
h5_int64_t herr;
|
||||
|
||||
printf ("PROC[%d]: Open file \"%s\" for reading ...\n",
|
||||
myproc, fname );
|
||||
|
||||
f = H5OpenFile ( fname, H5_O_RDONLY, comm );
|
||||
if ( f == H5_FAILURE ) return -1;
|
||||
|
||||
herr = H5SetStep ( f, timestep );
|
||||
if ( herr < 0 ) return herr;
|
||||
|
||||
if ( _read_data ( f, myproc, layout ) < 0 ) {
|
||||
printf ("Failed to read file \"%s\"\n", fname );
|
||||
return 2;
|
||||
}
|
||||
if ( _read_attributes ( f, myproc, comm ) < 0 ) {
|
||||
printf ("Failed to read attributes \"%s\"\n", fname );
|
||||
return 3;
|
||||
}
|
||||
|
||||
herr = H5CloseFile ( f );
|
||||
if ( herr < 0 ) return -1;
|
||||
h5_file_t file = H5OpenFile (fname, H5_O_RDONLY, H5_PROP_DEFAULT);
|
||||
H5SetStep (file, 0);
|
||||
|
||||
_read_data (file, myproc, layout);
|
||||
_read_attributes (file, myproc, comm);
|
||||
|
||||
H5CloseFile (file);
|
||||
|
||||
return 0;
|
||||
return H5_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -475,14 +438,12 @@ main (
|
||||
int argc,
|
||||
char **argv
|
||||
) {
|
||||
h5_int64_t verbosity = DEFAULT_VERBOSITY;
|
||||
char *fname;
|
||||
int myproc;
|
||||
int nprocs;
|
||||
int opt_with_ghosts = 0;
|
||||
int opt_read = 0;
|
||||
int opt_write = 0;
|
||||
struct H5BlockPartition *layout;
|
||||
MPI_Comm comm = MPI_COMM_WORLD;
|
||||
|
||||
if (argc == 1) {
|
||||
fprintf ( stderr,
|
||||
@@ -490,55 +451,63 @@ main (
|
||||
argv[0] );
|
||||
return 1;
|
||||
}
|
||||
while ( --argc ) {
|
||||
if ( strcmp ( argv[argc], "-r" ) == 0 )
|
||||
while (--argc) {
|
||||
if (strcmp (argv[argc], "-r") == 0)
|
||||
opt_read = 1;
|
||||
else if ( strcmp ( argv[argc], "-w" ) == 0 )
|
||||
else if (strcmp (argv[argc], "-w") == 0)
|
||||
opt_write = 1;
|
||||
else if ( strcmp ( argv[argc], "-g" ) == 0 )
|
||||
else if (strcmp (argv[argc], "-g") == 0)
|
||||
opt_with_ghosts = 1;
|
||||
else {
|
||||
fprintf ( stderr,
|
||||
"Illegal option %s\n\n"
|
||||
"Usage: %s -w -r -g\n",
|
||||
argv[argc], argv[0] );
|
||||
fprintf (stderr,
|
||||
"Illegal option %s\n\n"
|
||||
"Usage: %s -w -r -g\n",
|
||||
argv[argc], argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
MPI_Init( &argc, &argv );
|
||||
MPI_Comm_size ( comm, &nprocs );
|
||||
MPI_Comm_rank( comm, &myproc );
|
||||
switch ( nprocs ) {
|
||||
// initialize MPI & H5hut
|
||||
int comm_rank = 0;
|
||||
int comm_size = 1;
|
||||
MPI_Init (&argc, &argv);
|
||||
MPI_Comm comm = MPI_COMM_WORLD;
|
||||
MPI_Comm_rank (comm, &comm_rank);
|
||||
MPI_Comm_size (comm, &comm_size);
|
||||
|
||||
H5AbortOnError ();
|
||||
H5SetVerbosityLevel (verbosity);
|
||||
|
||||
switch (comm_size) {
|
||||
case 1:
|
||||
fname = "blockfile1.h5";
|
||||
layout = &Layout1[myproc];
|
||||
layout = &Layout1[comm_rank];
|
||||
break;
|
||||
case 8:
|
||||
if ( opt_with_ghosts ) {
|
||||
if (opt_with_ghosts) {
|
||||
fname = "blockfile8G.h5";
|
||||
layout = &Layout8G[myproc];
|
||||
layout = &Layout8G[comm_rank];
|
||||
} else {
|
||||
fname = "blockfile8.h5";
|
||||
layout = &Layout8[myproc];
|
||||
layout = &Layout8[comm_rank];
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
if ( opt_with_ghosts ) {
|
||||
if (opt_with_ghosts) {
|
||||
fname = "blockfile16G.h5";
|
||||
layout = &Layout16G[myproc];
|
||||
layout = &Layout16G[comm_rank];
|
||||
} else {
|
||||
fname = "blockfile16.h5";
|
||||
layout = &Layout16[myproc];
|
||||
layout = &Layout16[comm_rank];
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
if ( opt_with_ghosts ) {
|
||||
if (opt_with_ghosts) {
|
||||
fname = "blockfile32G.h5";
|
||||
layout = &Layout32G[myproc];
|
||||
layout = &Layout32G[comm_rank];
|
||||
} else {
|
||||
fname = "blockfile32.h5";
|
||||
layout = &Layout32[myproc];
|
||||
layout = &Layout32[comm_rank];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -546,23 +515,12 @@ main (
|
||||
return 1;
|
||||
}
|
||||
|
||||
H5SetVerbosityLevel ( 4 );
|
||||
|
||||
if ( opt_write ) {
|
||||
if ( _write_file ( fname, myproc, comm, layout ) < 0 ) {
|
||||
printf ("Failed to write file \"%s\"\n", fname );
|
||||
goto cleanup;
|
||||
}
|
||||
} else if ( opt_read ) {
|
||||
if ( _read_file ( fname, myproc, comm, layout ) < 0 ) {
|
||||
printf ("Failed to read file \"%s\"\n", fname );
|
||||
goto cleanup;
|
||||
}
|
||||
if (opt_write) {
|
||||
_write_file (fname, comm_rank, comm, layout);
|
||||
} else if (opt_read) {
|
||||
_read_file (fname, comm_rank, comm, layout);
|
||||
}
|
||||
printf ("Done.\n");
|
||||
|
||||
cleanup:
|
||||
MPI_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,320 +1,292 @@
|
||||
Program H5BlockParTestScalarFieldF
|
||||
IMPLICIT NONE
|
||||
#ifdef PARALLEL_IO
|
||||
INCLUDE 'mpif.h'
|
||||
#endif
|
||||
INCLUDE 'H5hutF.h'
|
||||
!
|
||||
! Copyright (c) 2006-2014, The Regents of the University of California,
|
||||
! through Lawrence Berkeley National Laboratory (subject to receipt of any
|
||||
! required approvals from the U.S. Dept. of Energy) and the Paul Scherrer
|
||||
! Institut (Switzerland). All rights reserved.!
|
||||
!
|
||||
! License: see file COPYING in top level of source distribution.
|
||||
!
|
||||
include 'H5hut.f90'
|
||||
|
||||
INTEGER :: nargs = 0
|
||||
INTEGER :: myproc = 0
|
||||
INTEGER :: nprocs = 1
|
||||
INTEGER :: comm = 0
|
||||
INTEGER :: mpi_err
|
||||
INTEGER*8 :: h5_err
|
||||
INTEGER :: i
|
||||
CHARACTER(LEN=32) :: arg_str
|
||||
INTEGER :: opt_read = 0
|
||||
INTEGER :: opt_write = 0
|
||||
INTEGER :: opt_with_ghosts = 0
|
||||
CHARACTER(LEN=128) :: fname
|
||||
INTEGER*8 :: layout (6)
|
||||
INTEGER*8 :: layout1 (6,1)
|
||||
INTEGER*8 :: layout8 (6,8)
|
||||
INTEGER*8 :: layout8g (6,8)
|
||||
INTEGER*8 :: layout16 (6,16)
|
||||
INTEGER*8 :: layout16g(6,16)
|
||||
INTEGER*8 :: layout32 (6,32)
|
||||
INTEGER*8 :: layout32g(6,32)
|
||||
program read_write_scalar_field
|
||||
use H5hut
|
||||
implicit none
|
||||
include 'mpif.h'
|
||||
|
||||
DATA layout1 / 1,64, 1,64, 1,512 /
|
||||
integer :: nargs = 0
|
||||
integer :: comm_rank = 0
|
||||
integer :: comm_size = 1
|
||||
integer :: comm = 0
|
||||
integer :: mpi_err
|
||||
integer*8 :: h5_err
|
||||
integer :: i
|
||||
character(len=32) :: arg_str
|
||||
integer :: opt_read = 0
|
||||
integer :: opt_write = 0
|
||||
integer :: opt_with_ghosts = 0
|
||||
character(len=128) :: fname
|
||||
integer*8 :: layout (6)
|
||||
integer*8 :: layout1 (6,1)
|
||||
integer*8 :: layout8 (6,8)
|
||||
integer*8 :: layout8g (6,8)
|
||||
integer*8 :: layout16 (6,16)
|
||||
integer*8 :: layout16g(6,16)
|
||||
integer*8 :: layout32 (6,32)
|
||||
integer*8 :: layout32g(6,32)
|
||||
|
||||
data layout1 / 1,64, 1,64, 1,512 /
|
||||
|
||||
DATA layout8 / 1,64, 1,64, 1, 64, &
|
||||
1,64, 1,64, 65,128, &
|
||||
1,64, 1,64, 129,192, &
|
||||
1,64, 1,64, 193,256, &
|
||||
1,64, 1,64, 257,320, &
|
||||
1,64, 1,64, 321,384, &
|
||||
1,64, 1,64, 385,448, &
|
||||
1,64, 1,64, 449,512 /
|
||||
data layout8 / 1,64, 1,64, 1, 64, &
|
||||
1,64, 1,64, 65,128, &
|
||||
1,64, 1,64, 129,192, &
|
||||
1,64, 1,64, 193,256, &
|
||||
1,64, 1,64, 257,320, &
|
||||
1,64, 1,64, 321,384, &
|
||||
1,64, 1,64, 385,448, &
|
||||
1,64, 1,64, 449,512 /
|
||||
|
||||
DATA layout8g / 1,64, 1,64, 1, 65, &
|
||||
1,64, 1,64, 64,129, &
|
||||
1,64, 1,64, 128,193, &
|
||||
1,64, 1,64, 192,257, &
|
||||
1,64, 1,64, 256,321, &
|
||||
1,64, 1,64, 320,385, &
|
||||
1,64, 1,64, 384,449, &
|
||||
1,64, 1,64, 448,512 /
|
||||
data layout8g / 1,64, 1,64, 1, 65, &
|
||||
1,64, 1,64, 64,129, &
|
||||
1,64, 1,64, 128,193, &
|
||||
1,64, 1,64, 192,257, &
|
||||
1,64, 1,64, 256,321, &
|
||||
1,64, 1,64, 320,385, &
|
||||
1,64, 1,64, 384,449, &
|
||||
1,64, 1,64, 448,512 /
|
||||
|
||||
DATA layout16 / 1,64, 1,32, 1, 64, &
|
||||
1,64, 33,64, 1, 64, &
|
||||
1,64, 1,32, 65,128, &
|
||||
1,64, 33,64, 65,128, &
|
||||
1,64, 1,32, 129,192, &
|
||||
1,64, 33,64, 129,192, &
|
||||
1,64, 1,32, 193,256, &
|
||||
1,64, 33,64, 193,256, &
|
||||
1,64, 1,32, 257,320, &
|
||||
1,64, 33,64, 257,320, &
|
||||
1,64, 1,32, 321,384, &
|
||||
1,64, 33,64, 321,384, &
|
||||
1,64, 1,32, 385,448, &
|
||||
1,64, 33,64, 385,448, &
|
||||
1,64, 1,32, 449,512, &
|
||||
1,64, 33,64, 449,512 /
|
||||
data layout16 / 1,64, 1,32, 1, 64, &
|
||||
1,64, 33,64, 1, 64, &
|
||||
1,64, 1,32, 65,128, &
|
||||
1,64, 33,64, 65,128, &
|
||||
1,64, 1,32, 129,192, &
|
||||
1,64, 33,64, 129,192, &
|
||||
1,64, 1,32, 193,256, &
|
||||
1,64, 33,64, 193,256, &
|
||||
1,64, 1,32, 257,320, &
|
||||
1,64, 33,64, 257,320, &
|
||||
1,64, 1,32, 321,384, &
|
||||
1,64, 33,64, 321,384, &
|
||||
1,64, 1,32, 385,448, &
|
||||
1,64, 33,64, 385,448, &
|
||||
1,64, 1,32, 449,512, &
|
||||
1,64, 33,64, 449,512 /
|
||||
|
||||
DATA layout16g/ 1,64, 1,33, 1, 65, &
|
||||
1,64, 32,64, 1, 65, &
|
||||
1,64, 1,33, 64,129, &
|
||||
1,64, 32,64, 64,129, &
|
||||
1,64, 1,33, 128,193, &
|
||||
1,64, 32,64, 128,193, &
|
||||
1,64, 1,33, 192,257, &
|
||||
1,64, 32,64, 192,257, &
|
||||
1,64, 1,33, 256,321, &
|
||||
1,64, 32,64, 256,321, &
|
||||
1,64, 1,33, 320,385, &
|
||||
1,64, 32,64, 320,385, &
|
||||
1,64, 1,33, 384,449, &
|
||||
1,64, 32,64, 384,449, &
|
||||
1,64, 1,33, 448,512, &
|
||||
1,64, 32,64, 448,512 /
|
||||
data layout16g/ 1,64, 1,33, 1, 65, &
|
||||
1,64, 32,64, 1, 65, &
|
||||
1,64, 1,33, 64,129, &
|
||||
1,64, 32,64, 64,129, &
|
||||
1,64, 1,33, 128,193, &
|
||||
1,64, 32,64, 128,193, &
|
||||
1,64, 1,33, 192,257, &
|
||||
1,64, 32,64, 192,257, &
|
||||
1,64, 1,33, 256,321, &
|
||||
1,64, 32,64, 256,321, &
|
||||
1,64, 1,33, 320,385, &
|
||||
1,64, 32,64, 320,385, &
|
||||
1,64, 1,33, 384,449, &
|
||||
1,64, 32,64, 384,449, &
|
||||
1,64, 1,33, 448,512, &
|
||||
1,64, 32,64, 448,512 /
|
||||
|
||||
DATA layout32 / 1,32, 1,32, 1, 64, &
|
||||
1,32, 33,64, 1, 64, &
|
||||
33,64, 1,32, 1, 64, &
|
||||
33,64, 33,64, 1, 64, &
|
||||
1,32, 1,32, 65,128, &
|
||||
1,32, 33,64, 65,128, &
|
||||
33,64, 1,32, 65,128, &
|
||||
33,64, 33,64, 65,128, &
|
||||
1,32, 1,32, 129,192, &
|
||||
1,32, 33,64, 129,192, &
|
||||
33,64, 1,32, 129,192, &
|
||||
33,64, 33,64, 129,192, &
|
||||
1,32, 1,32, 193,256, &
|
||||
1,32, 33,64, 193,256, &
|
||||
33,64, 1,32, 193,256, &
|
||||
33,64, 33,64, 193,256, &
|
||||
1,32, 1,32, 257,320, &
|
||||
1,32, 33,64, 257,320, &
|
||||
33,64, 1,32, 257,320, &
|
||||
33,64, 33,64, 257,320, &
|
||||
1,32, 1,32, 321,384, &
|
||||
1,32, 33,64, 321,384, &
|
||||
33,64, 1,32, 321,384, &
|
||||
33,64, 33,64, 321,384, &
|
||||
1,32, 1,32, 385,448, &
|
||||
1,32, 33,64, 385,448, &
|
||||
33,64, 1,32, 385,448, &
|
||||
33,64, 33,64, 385,448, &
|
||||
1,32, 1,32, 449,512, &
|
||||
1,32, 33,64, 449,512, &
|
||||
33,64, 1,32, 449,512, &
|
||||
33,64, 33,64, 449,512 /
|
||||
data layout32 / 1,32, 1,32, 1, 64, &
|
||||
1,32, 33,64, 1, 64, &
|
||||
33,64, 1,32, 1, 64, &
|
||||
33,64, 33,64, 1, 64, &
|
||||
1,32, 1,32, 65,128, &
|
||||
1,32, 33,64, 65,128, &
|
||||
33,64, 1,32, 65,128, &
|
||||
33,64, 33,64, 65,128, &
|
||||
1,32, 1,32, 129,192, &
|
||||
1,32, 33,64, 129,192, &
|
||||
33,64, 1,32, 129,192, &
|
||||
33,64, 33,64, 129,192, &
|
||||
1,32, 1,32, 193,256, &
|
||||
1,32, 33,64, 193,256, &
|
||||
33,64, 1,32, 193,256, &
|
||||
33,64, 33,64, 193,256, &
|
||||
1,32, 1,32, 257,320, &
|
||||
1,32, 33,64, 257,320, &
|
||||
33,64, 1,32, 257,320, &
|
||||
33,64, 33,64, 257,320, &
|
||||
1,32, 1,32, 321,384, &
|
||||
1,32, 33,64, 321,384, &
|
||||
33,64, 1,32, 321,384, &
|
||||
33,64, 33,64, 321,384, &
|
||||
1,32, 1,32, 385,448, &
|
||||
1,32, 33,64, 385,448, &
|
||||
33,64, 1,32, 385,448, &
|
||||
33,64, 33,64, 385,448, &
|
||||
1,32, 1,32, 449,512, &
|
||||
1,32, 33,64, 449,512, &
|
||||
33,64, 1,32, 449,512, &
|
||||
33,64, 33,64, 449,512 /
|
||||
|
||||
DATA layout32G/ 1,33, 1,33, 1, 65, &
|
||||
1,33, 32,64, 1, 65, &
|
||||
32,64, 1,33, 1, 65, &
|
||||
32,64, 32,64, 1, 65, &
|
||||
1,33, 1,33, 64,129, &
|
||||
1,33, 32,64, 64,129, &
|
||||
32,64, 1,33, 64,129, &
|
||||
32,64, 32,64, 64,129, &
|
||||
1,33, 1,33, 128,193, &
|
||||
1,33, 32,64, 128,193, &
|
||||
32,64, 1,33, 128,193, &
|
||||
32,64, 32,64, 128,193, &
|
||||
1,33, 1,33, 192,257, &
|
||||
1,33, 32,64, 192,257, &
|
||||
32,64, 1,33, 192,257, &
|
||||
32,64, 32,64, 192,257, &
|
||||
1,33, 1,33, 256,321, &
|
||||
1,33, 32,64, 256,321, &
|
||||
32,64, 1,33, 256,321, &
|
||||
32,64, 32,64, 256,321, &
|
||||
1,33, 1,33, 320,385, &
|
||||
1,33, 32,64, 320,385, &
|
||||
32,64, 1,33, 320,385, &
|
||||
32,64, 32,64, 320,385, &
|
||||
1,33, 1,33, 384,449, &
|
||||
1,33, 32,64, 384,449, &
|
||||
32,64, 1,33, 384,449, &
|
||||
32,64, 32,64, 384,449, &
|
||||
1,33, 1,33, 448,512, &
|
||||
1,33, 32,64, 448,512, &
|
||||
32,64, 1,33, 448,512, &
|
||||
32,64, 32,64, 448,512 /
|
||||
nargs = IARGC ()
|
||||
IF (nargs == 0) THEN
|
||||
PRINT *, "Usage: H5BlockExampleF -w | -r [-g]"
|
||||
CALL EXIT (1)
|
||||
END IF
|
||||
DO i = 1, nargs
|
||||
CALL GETARG ( i, arg_str )
|
||||
IF ( arg_str == "-r" ) THEN
|
||||
opt_read = 1
|
||||
ELSE IF ( arg_str == "-w" ) THEN
|
||||
opt_write = 1
|
||||
ELSE IF ( arg_str == "-g" ) THEN
|
||||
opt_with_ghosts = 1
|
||||
ELSE
|
||||
PRINT *, "Illegal option ", arg_str, "\n"
|
||||
PRINT *, "Usage: H5BlockExampleF -w | -r [-g]"
|
||||
CALL EXIT (1)
|
||||
END IF
|
||||
END DO
|
||||
data layout32g/ 1,33, 1,33, 1, 65, &
|
||||
1,33, 32,64, 1, 65, &
|
||||
32,64, 1,33, 1, 65, &
|
||||
32,64, 32,64, 1, 65, &
|
||||
1,33, 1,33, 64,129, &
|
||||
1,33, 32,64, 64,129, &
|
||||
32,64, 1,33, 64,129, &
|
||||
32,64, 32,64, 64,129, &
|
||||
1,33, 1,33, 128,193, &
|
||||
1,33, 32,64, 128,193, &
|
||||
32,64, 1,33, 128,193, &
|
||||
32,64, 32,64, 128,193, &
|
||||
1,33, 1,33, 192,257, &
|
||||
1,33, 32,64, 192,257, &
|
||||
32,64, 1,33, 192,257, &
|
||||
32,64, 32,64, 192,257, &
|
||||
1,33, 1,33, 256,321, &
|
||||
1,33, 32,64, 256,321, &
|
||||
32,64, 1,33, 256,321, &
|
||||
32,64, 32,64, 256,321, &
|
||||
1,33, 1,33, 320,385, &
|
||||
1,33, 32,64, 320,385, &
|
||||
32,64, 1,33, 320,385, &
|
||||
32,64, 32,64, 320,385, &
|
||||
1,33, 1,33, 384,449, &
|
||||
1,33, 32,64, 384,449, &
|
||||
32,64, 1,33, 384,449, &
|
||||
32,64, 32,64, 384,449, &
|
||||
1,33, 1,33, 448,512, &
|
||||
1,33, 32,64, 448,512, &
|
||||
32,64, 1,33, 448,512, &
|
||||
32,64, 32,64, 448,512 /
|
||||
nargs = iargc ()
|
||||
if (nargs == 0) then
|
||||
print *, "usage: read_write_scalarfield -w | -r [-g]"
|
||||
call exit (1)
|
||||
end if
|
||||
do i = 1, nargs
|
||||
call getarg (i, arg_str)
|
||||
if (arg_str == "-r") then
|
||||
opt_read = 1
|
||||
else if (arg_str == "-w") then
|
||||
opt_write = 1
|
||||
else if (arg_str == "-g") then
|
||||
opt_with_ghosts = 1
|
||||
else
|
||||
print *, "Illegal option ", arg_str, "\n"
|
||||
print *, "Usage: read_write_scalarfield -w | -r [-g]"
|
||||
call exit (1)
|
||||
end if
|
||||
end do
|
||||
|
||||
! init MPI & H5hut
|
||||
comm = MPI_COMM_WORLD
|
||||
call mpi_init(mpi_err)
|
||||
call mpi_comm_rank(comm, comm_rank, mpi_err)
|
||||
call mpi_comm_size (comm, comm_size, mpi_err)
|
||||
call h5_abort_on_error ()
|
||||
call h5_set_verbosity_level (511_8)
|
||||
|
||||
#ifdef PARALLEL_IO
|
||||
comm = MPI_COMM_WORLD
|
||||
CALL MPI_Init ( mpi_err )
|
||||
comm = MPI_COMM_WORLD
|
||||
CALL MPI_Comm_rank ( comm, myproc, mpi_err)
|
||||
CALL MPI_Comm_size ( comm, nprocs, mpi_err)
|
||||
#endif
|
||||
SELECTCASE ( nprocs )
|
||||
CASE ( 1 )
|
||||
fname = "blockfile1.h5"
|
||||
layout = layout1 ( :, myproc+1 )
|
||||
selectcase (comm_size)
|
||||
case (1)
|
||||
fname = "blockfile1.h5"
|
||||
layout = layout1 (:, comm_rank+1)
|
||||
|
||||
CASE ( 8 )
|
||||
IF ( opt_with_ghosts == 1 ) THEN
|
||||
fname = "blockfile8G.h5"
|
||||
layout = layout8g ( :, myproc+1 )
|
||||
ELSE
|
||||
fname = "blockfile8.h5"
|
||||
layout = layout8 ( :, myproc+1 )
|
||||
END IF
|
||||
case (8)
|
||||
if (opt_with_ghosts == 1) then
|
||||
fname = "blockfile8g.h5"
|
||||
layout = layout8g (:, comm_rank+1)
|
||||
else
|
||||
fname = "blockfile8.h5"
|
||||
layout = layout8 (:, comm_rank+1)
|
||||
end if
|
||||
|
||||
case (16)
|
||||
if (opt_with_ghosts == 1) then
|
||||
fname = "blockfile16g.h5"
|
||||
layout = layout16g (:, comm_rank+1)
|
||||
else
|
||||
fname = "blockfile16.h5"
|
||||
layout = layout16 (:, comm_rank+1)
|
||||
end if
|
||||
|
||||
case (32)
|
||||
if (opt_with_ghosts == 1) then
|
||||
fname = "blockfile32g.h5"
|
||||
layout = layout32g (:, comm_rank+1)
|
||||
else
|
||||
fname = "blockfile32.h5"
|
||||
layout = layout32 (:, comm_rank+1)
|
||||
end if
|
||||
|
||||
CASE ( 16 )
|
||||
IF ( opt_with_ghosts == 1 ) THEN
|
||||
fname = "blockfile16G.h5"
|
||||
layout = layout16g ( :, myproc+1 )
|
||||
ELSE
|
||||
fname = "blockfile16.h5"
|
||||
layout = layout16 ( :, myproc+1 )
|
||||
END IF
|
||||
case default
|
||||
print *, "Run this test on 1, 8, 16 or 32 cores!"
|
||||
call mpi_finalize
|
||||
call exit (1)
|
||||
end select
|
||||
|
||||
CASE ( 32 )
|
||||
IF ( opt_with_ghosts == 1 ) THEN
|
||||
fname = "blockfile32G.h5"
|
||||
layout = layout32g ( :, myproc+1 )
|
||||
ELSE
|
||||
fname = "blockfile32.h5"
|
||||
layout = layout32 ( :, myproc+1 )
|
||||
END IF
|
||||
|
||||
CASE DEFAULT
|
||||
PRINT *, "Run this test on 1, 8, 16 or 32 cores!"
|
||||
#ifdef PARALLEL_IO
|
||||
CALL MPI_Finalize
|
||||
#endif
|
||||
CALL EXIT (1)
|
||||
END SELECT
|
||||
|
||||
h5_err = h5_set_verbosity_level ( 511_8 )
|
||||
|
||||
IF ( opt_write == 1 ) THEN
|
||||
h5_err = write_file ( fname, myproc, comm, layout )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
PRINT "('[proc ', I3, ']: Faild to write file ', A, '!')", myproc, fname
|
||||
END IF
|
||||
|
||||
ELSE IF ( opt_read == 1 ) THEN
|
||||
h5_err = read_file ( fname, myproc, comm, layout )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
PRINT "('[proc ', I3, ']: Faild to read file ', A, '!')", myproc, fname
|
||||
END IF
|
||||
|
||||
ENDIF
|
||||
#ifdef PARALLEL_IO
|
||||
PRINT "('[proc ', I3, ']: Cleanup.')", myproc
|
||||
CALL MPI_Finalize
|
||||
#endif
|
||||
PRINT "('[proc ', I3, ']: Done.')", myproc
|
||||
CALL EXIT (0)
|
||||
if (opt_write == 1) then
|
||||
h5_err = write_file (fname, comm_rank, layout)
|
||||
if (h5_err < 0) then
|
||||
print "('[proc ', I3, ']: Faild to write file ', A, '!')", comm_rank, fname
|
||||
end if
|
||||
|
||||
else if (opt_read == 1) then
|
||||
h5_err = read_file (fname, comm_rank, layout)
|
||||
if (h5_err < 0) then
|
||||
print "('[proc ', I3, ']: Faild to read file ', A, '!')", comm_rank, fname
|
||||
end if
|
||||
|
||||
endif
|
||||
print "('[proc ', I3, ']: Cleanup.')", comm_rank
|
||||
call mpi_finalize
|
||||
print "('[proc ', I3, ']: Done.')", comm_rank
|
||||
call exit (0)
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!!
|
||||
CONTAINS
|
||||
contains
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!!
|
||||
INTEGER*8 FUNCTION write_file ( fname, myproc, comm, layout )
|
||||
IMPLICIT NONE
|
||||
integer*8 function write_file (fname, comm_rank, layout)
|
||||
use H5hut
|
||||
implicit none
|
||||
|
||||
CHARACTER(LEN=*), INTENT(IN) :: fname
|
||||
INTEGER, INTENT(IN) :: myproc
|
||||
INTEGER, INTENT(IN) :: comm
|
||||
INTEGER*8, INTENT(IN) :: layout(6)
|
||||
character(len=*), intent(in) :: fname
|
||||
integer, intent(in) :: comm_rank
|
||||
integer*8, intent(in) :: layout(6)
|
||||
|
||||
INCLUDE 'H5hutF.h'
|
||||
integer*8 :: file
|
||||
integer*8 :: timestep = 1
|
||||
|
||||
INTEGER*8 :: file
|
||||
INTEGER*8 :: timestep = 1
|
||||
print "('[proc ', I3, ']: Open file for writing ...')", comm_rank
|
||||
file = h5_openfile (fname, H5_O_WRONLY, H5_PROP_DEFAULT)
|
||||
h5_err = h5_setstep (file, timestep)
|
||||
h5_err = write_field (file, comm_rank, layout)
|
||||
h5_err = write_attributes (file)
|
||||
h5_err = h5_closefile (file)
|
||||
|
||||
PRINT "('[proc ', I3, ']: Open file for writing ...')", myproc
|
||||
#ifdef PARALLEL_IO
|
||||
file = h5_openw_par (fname, comm)
|
||||
#else
|
||||
file = h5_openw_par (fname)
|
||||
#endif
|
||||
IF ( file == 0 ) THEN
|
||||
write_file = -1
|
||||
RETURN
|
||||
ENDIF
|
||||
|
||||
h5_err = h5_setstep ( file, timestep )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
write_file = h5_err
|
||||
RETURN
|
||||
ENDIF
|
||||
|
||||
h5_err = write_field ( file, myproc, layout )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
write_file = h5_err
|
||||
RETURN
|
||||
ENDIF
|
||||
|
||||
h5_err = write_attributes ( file )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
write_file = h5_err
|
||||
RETURN
|
||||
ENDIF
|
||||
|
||||
h5_err = h5_close ( file )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
write_file = h5_err
|
||||
RETURN
|
||||
ENDIF
|
||||
|
||||
write_file = 0
|
||||
END FUNCTION write_file
|
||||
write_file = H5_SUCCESS
|
||||
end function write_file
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!!
|
||||
INTEGER*8 FUNCTION write_field ( file, myproc, layout )
|
||||
IMPLICIT NONE
|
||||
integer*8 function write_field (file, comm_rank, layout)
|
||||
use H5hut
|
||||
implicit none
|
||||
|
||||
INTEGER*8, INTENT(IN) :: file
|
||||
INTEGER, INTENT(IN) :: myproc
|
||||
INTEGER*8, INTENT(IN) :: layout(6)
|
||||
integer*8, intent(in) :: file
|
||||
integer, intent(in) :: comm_rank
|
||||
integer*8, intent(in) :: layout(6)
|
||||
|
||||
INCLUDE 'H5hutF.h'
|
||||
|
||||
INTEGER*8 :: i, j, k
|
||||
INTEGER*8 :: i_start
|
||||
INTEGER*8 :: i_end
|
||||
INTEGER*8 :: j_start
|
||||
INTEGER*8 :: j_end
|
||||
INTEGER*8 :: k_start
|
||||
INTEGER*8 :: k_end
|
||||
INTEGER*8 :: i_dims
|
||||
INTEGER*8 :: j_dims
|
||||
INTEGER*8 :: k_dims
|
||||
REAL*8 :: value
|
||||
integer*8 :: i, j, k
|
||||
integer*8 :: i_start
|
||||
integer*8 :: i_end
|
||||
integer*8 :: j_start
|
||||
integer*8 :: j_end
|
||||
integer*8 :: k_start
|
||||
integer*8 :: k_end
|
||||
integer*8 :: i_dims
|
||||
integer*8 :: j_dims
|
||||
integer*8 :: k_dims
|
||||
real*8 :: value
|
||||
|
||||
REAL*8, DIMENSION(:,:,:), ALLOCATABLE :: data
|
||||
real*8, dimension(:,:,:), allocatable :: data
|
||||
|
||||
i_start = layout(1)
|
||||
i_end = layout(2)
|
||||
@@ -326,176 +298,114 @@ Program H5BlockParTestScalarFieldF
|
||||
j_dims = j_end - j_start + 1
|
||||
k_dims = k_end - k_start + 1
|
||||
|
||||
ALLOCATE ( data (i_dims,j_dims, k_dims) )
|
||||
allocate ( data (i_dims,j_dims, k_dims) )
|
||||
|
||||
PRINT "('[proc ', I3, ']: Defining layout for writing ...')", myproc
|
||||
PRINT "('[proc ', I3, ']: ', I3, ':', I3, ', ', I3, ':', I3,', ', I3, ':', I3)", &
|
||||
myproc, &
|
||||
print "('[proc ', I3, ']: Defining layout for writing ...')", comm_rank
|
||||
print "('[proc ', I3, ']: ', I3, ':', I3, ', ', I3, ':', I3,', ', I3, ':', I3)", &
|
||||
comm_rank, &
|
||||
i_start, i_end, &
|
||||
j_start, j_end, &
|
||||
k_start, k_end
|
||||
|
||||
h5_err = h5bl_3d_setview ( file, i_start, i_end, j_start, j_end, k_start, k_end )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
write_field = h5_err
|
||||
RETURN
|
||||
END IF
|
||||
h5_err = h5bl_3d_setview (file, i_start, i_end, j_start, j_end, k_start, k_end)
|
||||
|
||||
DO i = 1, i_dims
|
||||
DO j = 1, j_dims
|
||||
DO k = 1, k_dims
|
||||
value = (k-1) + 1000*(j-1) + 100000*(i-1) + 10000000*myproc
|
||||
do i = 1, i_dims
|
||||
do j = 1, j_dims
|
||||
do k = 1, k_dims
|
||||
value = (k-1) + 1000*(j-1) + 100000*(i-1) + 10000000*comm_rank
|
||||
data(i,j,k) = value
|
||||
END DO
|
||||
END DO
|
||||
END DO
|
||||
end do
|
||||
end do
|
||||
end do
|
||||
|
||||
PRINT "('[proc ', I3, ']: Writing field ...')", myproc
|
||||
print "('[proc ', I3, ']: Writing field ...')", comm_rank
|
||||
h5_err = h5bl_3d_write_scalar_field_r8 ( file, "TestField", data )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
write_field = h5_err
|
||||
RETURN
|
||||
END IF
|
||||
|
||||
write_field = 0
|
||||
END FUNCTION write_field
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!!
|
||||
INTEGER*8 FUNCTION write_attributes ( file )
|
||||
IMPLICIT NONE
|
||||
INTEGER*8, INTENT(IN) :: file
|
||||
|
||||
INCLUDE 'H5hutF.h'
|
||||
integer*8 function write_attributes (file)
|
||||
use H5hut
|
||||
implicit none
|
||||
integer*8, intent(in) :: file
|
||||
integer*8 :: h5_err = 0
|
||||
character(len=128) :: s_val
|
||||
integer*8 :: i8_val(1)
|
||||
integer*4 :: i4_val(1)
|
||||
real*8 :: r8_val(1)
|
||||
real*4 :: r4_val(1)
|
||||
|
||||
INTEGER*8 :: h5_err = 0
|
||||
CHARACTER(LEN=128) :: s_val
|
||||
INTEGER*8 :: i8_val(1)
|
||||
INTEGER*4 :: i4_val(1)
|
||||
REAL*8 :: r8_val(1)
|
||||
REAL*4 :: r4_val(1)
|
||||
|
||||
PRINT "('[proc ', I3, ']: Writing string attribute ...')", myproc
|
||||
print "('[proc ', I3, ']: Writing string attribute ...')", comm_rank
|
||||
s_val = "42"
|
||||
h5_err = h5bl_writefieldattrib_string ( file, "TestField", "TestString", s_val )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
write_attributes = h5_err
|
||||
RETURN
|
||||
END IF
|
||||
|
||||
PRINT "('[proc ', I3, ']: Writing int64 attribute ...')", myproc
|
||||
print "('[proc ', I3, ']: Writing int64 attribute ...')", comm_rank
|
||||
i8_val(1) = 42
|
||||
h5_err = h5bl_writefieldattrib_i8 ( file, "TestField", "TestInt64", i8_val, 1_8 )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
write_attributes = h5_err
|
||||
RETURN
|
||||
END IF
|
||||
|
||||
PRINT "('[proc ', I3, ']: Writing int32 attribute ...')", myproc
|
||||
print "('[proc ', I3, ']: Writing int32 attribute ...')", comm_rank
|
||||
i4_val(1) = 42
|
||||
h5_err = h5bl_writefieldattrib_i4 ( file, "TestField", "TestInt32", i4_val, 1_8 )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
write_attributes = h5_err
|
||||
RETURN
|
||||
END IF
|
||||
|
||||
PRINT "('[proc ', I3, ']: Writing float64 attribute ...')", myproc
|
||||
print "('[proc ', I3, ']: Writing float64 attribute ...')", comm_rank
|
||||
r8_val(1) = 42.0
|
||||
h5_err = h5bl_writefieldattrib_r8 ( file, "TestField", "TestFloat64", r8_val, 1_8 )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
write_attributes = h5_err
|
||||
RETURN
|
||||
END IF
|
||||
|
||||
PRINT "('[proc ', I3, ']: Writing float32 attribute ...')", myproc
|
||||
print "('[proc ', I3, ']: Writing float32 attribute ...')", comm_rank
|
||||
r4_val(1) = 42.0
|
||||
h5_err = h5bl_writefieldattrib_r4 ( file, "TestField", "TestFloat32", r4_val, 1_8 )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
write_attributes = h5_err
|
||||
RETURN
|
||||
END IF
|
||||
|
||||
write_attributes = 0
|
||||
END FUNCTION write_attributes
|
||||
end function write_attributes
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!!
|
||||
INTEGER*8 FUNCTION read_file ( fname, myproc, comm, layout )
|
||||
IMPLICIT NONE
|
||||
integer*8 function read_file (fname, comm_rank, layout)
|
||||
use H5hut
|
||||
implicit none
|
||||
|
||||
CHARACTER(LEN=*), INTENT(IN) :: fname
|
||||
INTEGER, INTENT(IN) :: myproc
|
||||
INTEGER, INTENT(IN) :: comm
|
||||
INTEGER*8, INTENT(IN) :: layout(6)
|
||||
character(len=*), intent(in) :: fname
|
||||
integer, intent(in) :: comm_rank
|
||||
integer*8, intent(in) :: layout(6)
|
||||
integer*8 :: file
|
||||
integer*8 :: timestep = 1
|
||||
|
||||
INCLUDE 'H5hutF.h'
|
||||
print "('[proc ', I3, ']: Open file for reading ...')", comm_rank
|
||||
file = h5_openfile (FNAME, H5_O_WRONLY, H5_PROP_DEFAULT)
|
||||
h5_err = h5_setstep (file, timestep)
|
||||
|
||||
INTEGER*8 :: file
|
||||
INTEGER*8 :: timestep = 1
|
||||
|
||||
PRINT "('[proc ', I3, ']: Open file for reading ...')", myproc
|
||||
#ifdef PARALLEL_IO
|
||||
file = h5_openr_par ( fname, comm )
|
||||
#else
|
||||
file = h5_openr (fname
|
||||
#endif
|
||||
if ( file == 0 ) THEN
|
||||
read_file = -1
|
||||
RETURN
|
||||
ENDIF
|
||||
|
||||
h5_err = h5_setstep ( file, timestep )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
read_file = -1
|
||||
RETURN
|
||||
ENDIF
|
||||
|
||||
h5_err = read_field ( file, myproc, layout )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
read_file = -1
|
||||
RETURN
|
||||
ENDIF
|
||||
|
||||
h5_err = read_attributes ( file )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
read_file = -1
|
||||
RETURN
|
||||
ENDIF
|
||||
|
||||
h5_err = h5_close ( file )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
read_file = -1
|
||||
RETURN
|
||||
ENDIF
|
||||
h5_err = read_field (file, comm_rank, layout)
|
||||
h5_err = read_attributes (file)
|
||||
h5_err = h5_closefile (file)
|
||||
|
||||
read_file = 0
|
||||
END FUNCTION read_file
|
||||
end function read_file
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!!
|
||||
INTEGER*8 FUNCTION read_field ( file, myproc, layout )
|
||||
IMPLICIT NONE
|
||||
integer*8 function read_field (file, comm_rank, layout)
|
||||
use H5hut
|
||||
implicit none
|
||||
|
||||
INTEGER*8, INTENT(IN) :: file
|
||||
INTEGER, INTENT(IN) :: myproc
|
||||
INTEGER*8, INTENT(IN) :: layout(6)
|
||||
integer*8, intent(in) :: file
|
||||
integer, intent(in) :: comm_rank
|
||||
integer*8, intent(in) :: layout(6)
|
||||
|
||||
INCLUDE 'H5hutF.h'
|
||||
|
||||
INTEGER*8 :: i, j, k
|
||||
INTEGER*8 :: i_start, i_start2
|
||||
INTEGER*8 :: i_end, i_end2
|
||||
INTEGER*8 :: j_start, j_start2
|
||||
INTEGER*8 :: j_end, j_end2
|
||||
INTEGER*8 :: k_start, k_start2
|
||||
INTEGER*8 :: k_end, k_end2
|
||||
INTEGER*8 :: i_dims
|
||||
INTEGER*8 :: j_dims
|
||||
INTEGER*8 :: k_dims
|
||||
INTEGER*8 :: ri, rj, rk, proc
|
||||
REAL*8 :: value
|
||||
integer*8 :: i, j, k
|
||||
integer*8 :: i_start
|
||||
integer*8 :: i_end
|
||||
integer*8 :: j_start
|
||||
integer*8 :: j_end
|
||||
integer*8 :: k_start
|
||||
integer*8 :: k_end
|
||||
integer*8 :: i_dims
|
||||
integer*8 :: j_dims
|
||||
integer*8 :: k_dims
|
||||
real*8 :: value
|
||||
|
||||
REAL*8, DIMENSION(:,:,:), ALLOCATABLE :: data
|
||||
real*8, dimension(:,:,:), allocatable :: data
|
||||
|
||||
i_start = layout(1)
|
||||
i_end = layout(2)
|
||||
@@ -507,118 +417,84 @@ Program H5BlockParTestScalarFieldF
|
||||
j_dims = j_end - j_start + 1
|
||||
k_dims = k_end - k_start + 1
|
||||
|
||||
ALLOCATE ( data (i_dims, j_dims, k_dims) )
|
||||
allocate ( data (i_dims, j_dims, k_dims) )
|
||||
|
||||
PRINT "('[proc ', I3, ']: Defining layout for reading ...')", myproc
|
||||
PRINT "('[proc ', I3, ']: ', I3, ':', I3, ', ', I3, ':', I3,', ', I3, ':', I3)", &
|
||||
myproc, &
|
||||
print "('[proc ', I3, ']: Defining layout for reading ...')", comm_rank
|
||||
print "('[proc ', I3, ']: ', I3, ':', I3, ', ', I3, ':', I3,', ', I3, ':', I3)", &
|
||||
comm_rank, &
|
||||
i_start, i_end, &
|
||||
j_start, j_end, &
|
||||
k_start, k_end
|
||||
|
||||
h5_err = h5bl_3d_setview ( file, i_start, i_end, j_start, j_end, k_start, k_end )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
read_field = -1
|
||||
RETURN
|
||||
END IF
|
||||
|
||||
PRINT "('[proc ', I3, ']: Reading field ...')", myproc
|
||||
print "('[proc ', I3, ']: Reading field ...')", comm_rank
|
||||
h5_err = h5bl_3d_read_scalar_field_r8 ( file, "TestField", data )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
read_field = -1
|
||||
RETURN
|
||||
END IF
|
||||
|
||||
DO i = 1, i_dims
|
||||
DO j = 1, j_dims
|
||||
DO k = 1, k_dims
|
||||
value = (k-1) + 1000*(j-1) + 100000*(i-1) + 10000000*myproc
|
||||
if ( data(i,j,k) /= value ) THEN
|
||||
PRINT "('[proc ', I3, ']: error: data(',I4,',',I4,',',I4,') = ',F10.2,' /= ',F10.2)", &
|
||||
do i = 1, i_dims
|
||||
do j = 1, j_dims
|
||||
do k = 1, k_dims
|
||||
value = (k-1) + 1000*(j-1) + 100000*(i-1) + 10000000*comm_rank
|
||||
if (data(i,j,k) /= value) then
|
||||
print "('[proc ', I3, ']: error: data(',I4,',',I4,',',I4,') = ',F10.2,' /= ',F10.2)", &
|
||||
i, j, k, data(i,j,k), value
|
||||
read_field = -2
|
||||
RETURN
|
||||
END IF
|
||||
END DO
|
||||
END DO
|
||||
END DO
|
||||
return
|
||||
end if
|
||||
end do
|
||||
end do
|
||||
end do
|
||||
read_field = 0
|
||||
END FUNCTION read_field
|
||||
end function read_field
|
||||
|
||||
INTEGER*8 FUNCTION read_attributes ( file )
|
||||
IMPLICIT NONE
|
||||
INTEGER*8, INTENT(IN) :: file
|
||||
integer*8 function read_attributes (file)
|
||||
use H5hut
|
||||
implicit none
|
||||
integer*8, intent(in) :: file
|
||||
|
||||
INCLUDE 'H5hutF.h'
|
||||
integer*8 :: h5_err = 0
|
||||
character(len=128) :: s_val
|
||||
integer*8 :: i8_val(1)
|
||||
integer*4 :: i4_val(1)
|
||||
real*8 :: r8_val(1)
|
||||
real*4 :: r4_val(1)
|
||||
|
||||
INTEGER*8 :: h5_err = 0
|
||||
CHARACTER(LEN=128) :: s_val
|
||||
INTEGER*8 :: i8_val(1)
|
||||
INTEGER*4 :: i4_val(1)
|
||||
REAL*8 :: r8_val(1)
|
||||
REAL*4 :: r4_val(1)
|
||||
|
||||
PRINT "('[proc ', I3, ']: Reading string attribute ...')", myproc
|
||||
print "('[proc ', I3, ']: Reading string attribute ...')", comm_rank
|
||||
h5_err = h5bl_readfieldattrib_string ( file, "TestField", "TestString", s_val )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
PRINT "('[proc ', I3, ']: Oops ...')", myproc
|
||||
read_attributes = h5_err
|
||||
RETURN
|
||||
END IF
|
||||
IF ( s_val /= "42" ) THEN
|
||||
PRINT "('[proc ', I3, ']: Error reading string attribute: Value is ', A, ' but should be 42')", &
|
||||
myproc, s_val
|
||||
END IF
|
||||
print "('[proc ', I3, ']: Error reading string attribute: Value is ', A, ' but should be 42')", &
|
||||
comm_rank, s_val
|
||||
end if
|
||||
|
||||
PRINT "('[proc ', I3, ']: Reading int64 attribute ...')", myproc
|
||||
print "('[proc ', I3, ']: Reading int64 attribute ...')", comm_rank
|
||||
h5_err = h5bl_readfieldattrib_i8 ( file, "TestField", "TestInt64", i8_val )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
PRINT "('[proc ', I3, ']: Oops ...')", myproc
|
||||
read_attributes = h5_err
|
||||
RETURN
|
||||
END IF
|
||||
IF ( i8_val(1) /= 42 ) THEN
|
||||
PRINT "('[proc ', I3, ']: Error reading int64 attribute: Value is ', I8, ' but should be 42')", &
|
||||
myproc, i8_val(1)
|
||||
END IF
|
||||
if ( i8_val(1) /= 42 ) then
|
||||
print "('[proc ', I3, ']: Error reading int64 attribute: Value is ', I8, ' but should be 42')", &
|
||||
comm_rank, i8_val(1)
|
||||
end if
|
||||
|
||||
PRINT "('[proc ', I3, ']: Reading int32 attribute ...')", myproc
|
||||
print "('[proc ', I3, ']: Reading int32 attribute ...')", comm_rank
|
||||
h5_err = h5bl_readfieldattrib_i4 ( file, "TestField", "TestInt32", i4_val )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
PRINT "('[proc ', I3, ']: Oops ...')", myproc
|
||||
read_attributes = h5_err
|
||||
RETURN
|
||||
END IF
|
||||
IF ( i4_val(1) /= 42 ) THEN
|
||||
PRINT "('[proc ', I3, ']: Error reading int32 attribute: Value is ', I8, ' but should be 42')", &
|
||||
myproc, i4_val(1)
|
||||
END IF
|
||||
if ( i4_val(1) /= 42 ) then
|
||||
print "('[proc ', I3, ']: Error reading int32 attribute: Value is ', I8, ' but should be 42')", &
|
||||
comm_rank, i4_val(1)
|
||||
end if
|
||||
|
||||
PRINT "('[proc ', I3, ']: Reading float64 attribute ...')", myproc
|
||||
print "('[proc ', I3, ']: Reading float64 attribute ...')", comm_rank
|
||||
h5_err = h5bl_readfieldattrib_r8 ( file, "TestField", "TestFloat64", r8_val )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
PRINT "('[proc ', I3, ']: Oops ...')", myproc
|
||||
read_attributes = h5_err
|
||||
RETURN
|
||||
END IF
|
||||
IF ( r8_val(1) /= 42.0 ) THEN
|
||||
PRINT "('[proc ', I3, ']: Error reading float64 attribute: Value is ', F10.2, ' but should be 42.0')", &
|
||||
myproc, r8_val(1)
|
||||
END IF
|
||||
if ( r8_val(1) /= 42.0 ) then
|
||||
print "('[proc ', I3, ']: Error reading float64 attribute: Value is ', F10.2, ' but should be 42.0')", &
|
||||
comm_rank, r8_val(1)
|
||||
end if
|
||||
|
||||
PRINT "('[proc ', I3, ']: Reading float32 attribute ...')", myproc
|
||||
print "('[proc ', I3, ']: Reading float32 attribute ...')", comm_rank
|
||||
h5_err = h5bl_readfieldattrib_r4 ( file, "TestField", "TestFloat32", r4_val )
|
||||
IF ( h5_err < 0 ) THEN
|
||||
PRINT "('[proc ', I3, ']: Oops ...')", myproc
|
||||
read_attributes = h5_err
|
||||
RETURN
|
||||
END IF
|
||||
IF ( r4_val(1) /= 42.0 ) THEN
|
||||
PRINT "('[proc ', I3, ']: Error reading float32 attribute: Value is ', F10.2, ' but should be 42.0')", &
|
||||
myproc, r4_val(1)
|
||||
END IF
|
||||
if ( r4_val(1) /= 42.0 ) then
|
||||
print "('[proc ', I3, ']: Error reading float32 attribute: Value is ', F10.2, ' but should be 42.0')", &
|
||||
comm_rank, r4_val(1)
|
||||
end if
|
||||
|
||||
read_attributes = h5_err
|
||||
END FUNCTION read_attributes
|
||||
end function read_attributes
|
||||
|
||||
END PROGRAM
|
||||
end program
|
||||
|
||||
Reference in New Issue
Block a user