test/H5BlockWriteScalarField1Proc.c
test/H5BlockTest1.c test/H5BlockReadParallel1.c test/H5BlockReadScalarField1Proc.c test/H5BlockWrite1.c test/H5BlockParallelTest1.c - removed
This commit is contained in:
@@ -99,12 +99,6 @@ test/BlockTestSpecs.txt -text
|
||||
test/H5BlockDissolveGhosts.c -text
|
||||
test/H5BlockParTestScalarField.c -text
|
||||
test/H5BlockParTestScalarField.pbs -text
|
||||
test/H5BlockParallelTest1.c -text
|
||||
test/H5BlockReadParallel1.c -text
|
||||
test/H5BlockReadScalarField1Proc.c -text
|
||||
test/H5BlockTest1.c -text
|
||||
test/H5BlockWrite1.c -text
|
||||
test/H5BlockWriteScalarField1Proc.c -text
|
||||
test/H5ParallelTest.cc -text
|
||||
test/H5PartAndreasTest.cc -text
|
||||
test/H5PartTest.cc -text
|
||||
|
||||
@@ -1,207 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <hdf5.h>
|
||||
#include "H5Part.h"
|
||||
#include "H5Block.h"
|
||||
|
||||
#if 0
|
||||
int ReadFile(const char *fn){
|
||||
char name[64];
|
||||
H5PartFile *file;
|
||||
h5part_int64_t i,t,nt,nds,myproc;
|
||||
unsigned int steps;
|
||||
printf ( "Open %s\n", fn );
|
||||
|
||||
file = H5PartOpenFile (fn, H5PART_READ);
|
||||
|
||||
nt=H5PartGetNumSteps(file);
|
||||
H5PartSetStep(file,0);
|
||||
nds=H5PartGetNumDatasets(file);
|
||||
|
||||
printf ( "Timesteps = %d; dataSets per timestep = %d\n", nt, nds );
|
||||
printf ( "\n\n===============================" );
|
||||
for(i=0;i<nds;i++){
|
||||
H5PartGetDatasetName(file,i,name,64);
|
||||
printf("\tDataset[%u] name=[%s]\n",
|
||||
i,name);
|
||||
}
|
||||
printf ( "===============================\n\n" );
|
||||
|
||||
for (steps=0; steps<nt; steps++) {
|
||||
H5PartSetStep(file,steps);
|
||||
h5part_int64_t n = H5PartGetNumParticles(file);
|
||||
printf ( "number of particles this step = %d\n", n );
|
||||
double *x = malloc ( n * sizeof ( *x ) );
|
||||
double *y = malloc ( n * sizeof ( *y ) );
|
||||
double *z = malloc ( n * sizeof ( *z ) );
|
||||
double *px= malloc ( n * sizeof ( *px ) );
|
||||
double *py= malloc ( n * sizeof ( *py ) );
|
||||
double *pz= malloc ( n * sizeof ( *pz ) );
|
||||
h5part_int64_t *id = malloc ( n * sizeof ( *id ) );
|
||||
|
||||
H5PartReadParticleStep(file,steps,x,y,z,px,py,pz,id);
|
||||
|
||||
double sumx = 0.0;
|
||||
double sumpz = 0.0;
|
||||
for ( i=0; i<n; i++ ) {
|
||||
sumx += x[i];
|
||||
sumpz += pz[i];
|
||||
}
|
||||
|
||||
printf ("\tstep=%d sum(x)= %d sum(pz)=%d\n",
|
||||
steps, sumx, sumpz );
|
||||
printf ("\tfirst x is %d\tlast x is %d\n",
|
||||
x[0], x[n-1] );
|
||||
printf ("\tFor fake data, expect sumx to be = %f\n",
|
||||
x[0]*((double)n) );
|
||||
free ( x );
|
||||
free ( y );
|
||||
free ( z );
|
||||
free ( px );
|
||||
free ( py );
|
||||
free ( pz );
|
||||
free ( id );
|
||||
}
|
||||
{
|
||||
h5part_float64_t *data = malloc ( 4*6*8* sizeof(*data) );
|
||||
h5part_int64_t herr;
|
||||
h5part_int64_t i, j, k;
|
||||
h5part_int64_t i_max, j_max, k_max;
|
||||
|
||||
i_max = 3;
|
||||
j_max = 5;
|
||||
k_max = 7;
|
||||
|
||||
herr = H5BlockOpen ( file );
|
||||
if ( herr < 0 ) {
|
||||
printf ("Ops!\n");
|
||||
exit ( 2 );
|
||||
}
|
||||
|
||||
herr = H5BlockDefine3DFieldLayout ( file, 0, i_max, 0, j_max, 0, k_max );
|
||||
if ( herr < 0 ) {
|
||||
printf ("Ops!\n");
|
||||
exit ( 2 );
|
||||
}
|
||||
|
||||
herr = H5Block3dReadScalarField ( file, "test", data );
|
||||
if ( herr < 0 ) {
|
||||
printf ("Ops!\n");
|
||||
exit ( 2 );
|
||||
}
|
||||
|
||||
for ( i = 0; i <= i_max; i++ ) {
|
||||
for ( j = 0; j <= j_max; j++ ) {
|
||||
for ( k = 0; k <= k_max; k++ ) {
|
||||
if ( *(data+ i + j*(i_max+1) + k*(i_max+1)*(j_max+1)) != i + 100*j + 10000*k ) {
|
||||
printf ( "Block data error!\n" );
|
||||
exit ( 2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i_max = 2;
|
||||
j_max = 2;
|
||||
k_max = 2;
|
||||
|
||||
herr = H5BlockDefine3DFieldLayout ( file, 0, i_max, 0, j_max, 0, k_max );
|
||||
if ( herr < 0 ) {
|
||||
printf ("Ops!\n");
|
||||
exit ( 2 );
|
||||
}
|
||||
herr = H5Block3dReadScalarField ( file, "test", data );
|
||||
if ( herr < 0 ) {
|
||||
printf ("Ops!\n");
|
||||
exit ( 2 );
|
||||
}
|
||||
|
||||
for ( i = 0; i <= i_max; i++ ) {
|
||||
for ( j = 0; j <= j_max; j++ ) {
|
||||
for ( k = 0; k <= k_max; k++ ) {
|
||||
printf ( "%f\n", *(data+ i + j*(i_max+1) + k*(i_max+1)*(j_max+1)) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
herr = H5BlockClose ( file );
|
||||
if ( herr < 0 ) {
|
||||
printf ("Ops!\n");
|
||||
exit ( 2 );
|
||||
}
|
||||
|
||||
free ( data );
|
||||
}
|
||||
|
||||
H5PartCloseFile(file);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int WriteFile(const char *fn){
|
||||
H5PartFile *f;
|
||||
h5part_int64_t i, j, k;
|
||||
int timestep;
|
||||
int timesteps = 5;
|
||||
h5part_int64_t herr;
|
||||
h5part_float64_t *data;
|
||||
h5part_int64_t i_dims, j_dims, k_dims;
|
||||
|
||||
printf ("Open %s\n", fn );
|
||||
|
||||
f = H5PartOpenFileParallel ( fn, H5PART_WRITE, MPI_COMM_WORLD );
|
||||
herr = H5BlockOpen ( f );
|
||||
if ( herr < 0 ) exit ( 2 );
|
||||
|
||||
for ( timestep = 0; timestep < timesteps; timestep++){
|
||||
herr = H5PartSetStep ( f, timestep );
|
||||
if ( herr < 0 ) exit ( 2 );
|
||||
|
||||
printf ( "Write Step %d\n", timestep );
|
||||
|
||||
i_dims = 4;
|
||||
j_dims = 6;
|
||||
k_dims = 8;
|
||||
|
||||
data = (h5part_float64_t*) malloc ( i_dims * j_dims * k_dims * sizeof(*data) );
|
||||
for ( i = 0; i < i_dims; i++ ) {
|
||||
for ( j = 0; j < j_dims; j++ ) {
|
||||
for ( k = 0; k < k_dims; k++ ) {
|
||||
*(data+ i + j*i_dims + k*i_dims*j_dims) = i+ 10*j + 100*k + 1000*f->myproc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
herr = H5BlockDefine3DFieldLayout ( f, f->myproc*2, f->myproc*2+i_dims-1, 0, j_dims-1, 0, k_dims-1 );
|
||||
if ( herr < 0 ) exit ( 2 );
|
||||
herr = H5Block3dWriteScalarField ( f, "test", data );
|
||||
if ( herr < 0 ) exit ( 2 );
|
||||
free ( data );
|
||||
}
|
||||
herr = H5BlockClose ( f );
|
||||
if ( herr < 0 ) exit ( 2 );
|
||||
|
||||
H5PartCloseFile ( f );
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc,char **argv){
|
||||
char *fn = "testfile.h5";
|
||||
|
||||
MPI_Init(&argc,&argv);
|
||||
H5PartSetVerbosityLevel ( 40 );
|
||||
|
||||
if(!WriteFile(fn)){
|
||||
printf ("Failed to write file %s\n", fn );
|
||||
exit ( 2 );
|
||||
}
|
||||
#if 0
|
||||
if(!ReadFile(fn)){
|
||||
printf ("Failed to read file %s\n", fn );
|
||||
exit ( 2 );
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,224 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <hdf5.h>
|
||||
#include "H5Part.h"
|
||||
#include "H5Block.h"
|
||||
#include <mpi.h>
|
||||
|
||||
|
||||
static h5part_int64_t
|
||||
calc_index_KJI (
|
||||
h5part_int64_t i,
|
||||
h5part_int64_t x_extent,
|
||||
h5part_int64_t j,
|
||||
h5part_int64_t y_extent,
|
||||
h5part_int64_t k,
|
||||
h5part_int64_t z_extent
|
||||
) {
|
||||
return i + j*x_extent + k*x_extent*y_extent;
|
||||
}
|
||||
|
||||
static int
|
||||
_define_3dlayout (
|
||||
H5PartFile *f,
|
||||
h5part_int64_t *dims,
|
||||
int myproc
|
||||
) {
|
||||
|
||||
h5part_int64_t i_start = 0;
|
||||
h5part_int64_t i_end = 63;
|
||||
h5part_int64_t j_start = 0;
|
||||
h5part_int64_t j_end = 63;
|
||||
h5part_int64_t k_start = 64 * myproc;
|
||||
h5part_int64_t k_end = k_start + 63;
|
||||
|
||||
herr_t herr = H5BlockDefine3DFieldLayout ( f,
|
||||
i_start, i_end,
|
||||
j_start, j_end,
|
||||
k_start, k_end );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
dims[0] = i_end - i_start + 1;
|
||||
dims[1] = j_end - j_start + 1;
|
||||
dims[2] = k_end - k_start + 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
_read3d_scalar (
|
||||
H5PartFile *f,
|
||||
const char *name,
|
||||
h5part_int64_t *dims,
|
||||
int myproc
|
||||
|
||||
) {
|
||||
h5part_float64_t *data;
|
||||
int i, j, k, idx;
|
||||
|
||||
data = (h5part_float64_t*) malloc (
|
||||
dims[0] * dims[1] * dims[2] * sizeof(*data) );
|
||||
|
||||
herr_t herr = H5Block3dReadScalarField ( f, name, data );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
for ( i = 0; i < dims[0]; i++ ) {
|
||||
for ( j = 0; j < dims[1]; j++ ) {
|
||||
printf ("(%d,%d,0): ", i, j );
|
||||
for ( k = 0; k < dims[2]; k++ ) {
|
||||
idx = calc_index_KJI ( i, dims[0], j, dims[1], k, dims[2] );
|
||||
printf ( "%.0f ", *(data+idx) );
|
||||
}
|
||||
printf ( "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_read3d_3d_vector (
|
||||
H5PartFile *f,
|
||||
const char *name,
|
||||
h5part_int64_t *dims
|
||||
|
||||
) {
|
||||
h5part_float64_t *x_data;
|
||||
h5part_float64_t *y_data;
|
||||
h5part_float64_t *z_data;
|
||||
|
||||
x_data = (h5part_float64_t*) malloc (
|
||||
dims[0] * dims[1] * dims[2] * sizeof(*x_data) );
|
||||
y_data = (h5part_float64_t*) malloc (
|
||||
dims[0] * dims[1] * dims[2] * sizeof(*y_data) );
|
||||
z_data = (h5part_float64_t*) malloc (
|
||||
dims[0] * dims[1] * dims[2] * sizeof(*z_data) );
|
||||
|
||||
herr_t herr = H5Block3dRead3dVectorField ( f, name,
|
||||
x_data, y_data, z_data );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_read_field (
|
||||
H5PartFile *f,
|
||||
h5part_int64_t idx,
|
||||
int myproc
|
||||
) {
|
||||
|
||||
char name[256];
|
||||
h5part_int64_t grid_rank;
|
||||
h5part_int64_t grid_dims[16];
|
||||
h5part_int64_t field_dims;
|
||||
|
||||
herr_t herr = H5BlockGetFieldInfo (
|
||||
f,
|
||||
idx,
|
||||
name, sizeof(name),
|
||||
&grid_rank,
|
||||
grid_dims,
|
||||
&field_dims );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
printf ( "Field #%lld has name \"%s\"\n", (long long) idx, name );
|
||||
|
||||
switch ( grid_rank ) {
|
||||
case 3:
|
||||
printf ( "\tGrid dimension of \"%s\" is 3\n", name );
|
||||
printf ( "\tThe dimesion sizes are: (%lld, %lld, %lld)\n",
|
||||
(long long)grid_dims[0], (long long)grid_dims[1], (long long)grid_dims[2] );
|
||||
if ( field_dims == 1 ) {
|
||||
printf ( "\tField data are scalar\n" );
|
||||
} else {
|
||||
printf ( "\tField data are %lld vectors\n",
|
||||
(long long)field_dims );
|
||||
}
|
||||
_define_3dlayout ( f, grid_dims, myproc );
|
||||
|
||||
if ( field_dims == 1 ) {
|
||||
_read3d_scalar ( f, name, grid_dims, myproc );
|
||||
} else if ( field_dims == 3 ) {
|
||||
_read3d_3d_vector ( f, name, grid_dims );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf ( "unknown grid rank %lld!!!\n", (long long)grid_rank );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
ReadFile (
|
||||
const char *fn,
|
||||
MPI_Comm comm,
|
||||
int myproc
|
||||
) {
|
||||
|
||||
H5PartFile *f;
|
||||
h5part_int64_t herr;
|
||||
|
||||
h5part_int64_t timestep;
|
||||
h5part_int64_t timesteps;
|
||||
|
||||
h5part_int64_t i, n;
|
||||
|
||||
printf ("Opening file %s for reading\n", fn );
|
||||
|
||||
f = H5PartOpenFileParallel ( fn, H5PART_READ, comm );
|
||||
if ( f == NULL ) return -1;
|
||||
|
||||
timesteps = H5PartGetNumSteps ( f );
|
||||
|
||||
printf ( "Timesteps = %lld\n", (long long)timesteps );
|
||||
printf ( "\n===============================\n" );
|
||||
|
||||
for ( timestep = 0; timestep < timesteps; timestep++) {
|
||||
herr = H5PartSetStep ( f, timestep );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
n = H5BlockGetNumFields ( f );
|
||||
if ( n < 0 ) return -1;
|
||||
printf ( "Number of fields in time-step #%lld: %lld \n",
|
||||
(long long)timestep, (long long)n );
|
||||
|
||||
for ( i = 0; i < n; i++ ) {
|
||||
_read_field ( f, i, myproc );
|
||||
|
||||
}
|
||||
}
|
||||
return H5PartCloseFile ( f );
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char **argv
|
||||
|
||||
) {
|
||||
|
||||
char *fn = "blockfile1.h5";
|
||||
int myproc;
|
||||
int nprocs;
|
||||
|
||||
H5PartSetVerbosityLevel ( 10 );
|
||||
|
||||
MPI_Comm comm=MPI_COMM_WORLD;
|
||||
|
||||
MPI_Init(&argc,&argv);
|
||||
MPI_Comm_size(comm,&nprocs);
|
||||
MPI_Comm_rank(comm,&myproc);
|
||||
|
||||
|
||||
if ( ReadFile ( fn, comm, 1 ) < 0 ){
|
||||
printf ("Failed to read file %s\n", fn );
|
||||
exit ( 2 );
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <hdf5.h>
|
||||
#include "H5Part.h"
|
||||
#include "H5Block.h"
|
||||
#include "H5BlockTypes.h"
|
||||
|
||||
struct H5BlockPartition Layout[1] = {
|
||||
{ 0, 63, 0, 63, 0, 511 }
|
||||
};
|
||||
|
||||
static h5part_int64_t
|
||||
_calc_index_KJI (
|
||||
int myproc,
|
||||
h5part_int64_t i,
|
||||
h5part_int64_t j,
|
||||
h5part_int64_t k
|
||||
) {
|
||||
h5part_int64_t i_dims = Layout[myproc].i_end - Layout[myproc].i_start + 1;
|
||||
h5part_int64_t j_dims = Layout[myproc].j_end - Layout[myproc].j_start + 1;
|
||||
|
||||
return i + j*i_dims + k*i_dims*j_dims;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static h5part_int64_t
|
||||
_read_file (
|
||||
H5PartFile *f,
|
||||
int myproc,
|
||||
int nprocs
|
||||
){
|
||||
|
||||
h5part_int64_t i, j, k, idx;
|
||||
h5part_int64_t herr;
|
||||
h5part_float64_t *data;
|
||||
h5part_int64_t i_dims = Layout[myproc].i_end - Layout[myproc].i_start + 1;
|
||||
h5part_int64_t j_dims = Layout[myproc].j_end - Layout[myproc].j_start + 1;
|
||||
h5part_int64_t k_dims = Layout[myproc].k_end - Layout[myproc].k_start + 1;
|
||||
|
||||
|
||||
printf ( "Reading Step #%lld\n", (long long)f->timestep );
|
||||
|
||||
data = malloc ( i_dims * j_dims * k_dims * sizeof ( *data ) );
|
||||
|
||||
herr = H5BlockDefine3DFieldLayout (
|
||||
f,
|
||||
Layout[myproc].i_start, Layout[myproc].i_end,
|
||||
Layout[myproc].j_start, Layout[myproc].j_end,
|
||||
Layout[myproc].k_start, Layout[myproc].k_end );
|
||||
if ( herr < 0 ) return herr;
|
||||
|
||||
herr = H5Block3dReadScalarField ( 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++ ) {
|
||||
idx = _calc_index_KJI ( myproc, i, j, k );
|
||||
h5part_float64_t val = k
|
||||
+ 1000*j
|
||||
+ 100000*i
|
||||
+ 10000000*myproc;
|
||||
if ( *(data + idx) != val ) {
|
||||
printf ( "Error reading field at [%lld,%lld,%lld]\n",
|
||||
(long long)i,
|
||||
(long long)j,
|
||||
(long long)k );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
free ( data );
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char **argv
|
||||
) {
|
||||
char *fname = "blockfile1.h5";
|
||||
int timestep = 0;
|
||||
int myproc;
|
||||
int nprocs;
|
||||
h5part_int64_t herr;
|
||||
H5PartFile *f;
|
||||
MPI_Comm comm = MPI_COMM_WORLD;
|
||||
|
||||
MPI_Init( &argc, &argv );
|
||||
MPI_Comm_size ( comm, &nprocs );
|
||||
MPI_Comm_rank( comm, &myproc );
|
||||
|
||||
if ( nprocs != 1 ) {
|
||||
printf ( "Run this test with 1 processor!" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf ("PROC[%d]: Open file \"%s\" for reading ...\n", myproc, fname );
|
||||
|
||||
f = H5PartOpenFileParallel ( fname, H5PART_READ, comm );
|
||||
if ( f == NULL ) return -1;
|
||||
|
||||
herr = H5PartSetStep ( f, timestep );
|
||||
if ( herr < 0 ) return herr;
|
||||
|
||||
|
||||
H5PartSetVerbosityLevel ( 40 );
|
||||
|
||||
if ( _read_file ( f, myproc, nprocs ) < 0 ) {
|
||||
printf ("Failed to read file \"%s\"\n", fname );
|
||||
return 2;
|
||||
}
|
||||
|
||||
char sval[16];
|
||||
herr = H5BlockReadFieldAttrib (
|
||||
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 );
|
||||
}
|
||||
|
||||
h5part_int64_t ival[1];
|
||||
h5part_float64_t rval[1];
|
||||
herr = H5BlockReadFieldAttrib (
|
||||
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] );
|
||||
}
|
||||
|
||||
herr = H5BlockReadFieldAttrib (
|
||||
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] );
|
||||
}
|
||||
|
||||
|
||||
herr = H5PartCloseFile ( f );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,311 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <hdf5.h>
|
||||
#include "H5Part.h"
|
||||
#include "H5Block.h"
|
||||
|
||||
|
||||
static h5part_int64_t
|
||||
calc_index_KJI (
|
||||
h5part_int64_t i,
|
||||
h5part_int64_t x_extent,
|
||||
h5part_int64_t j,
|
||||
h5part_int64_t y_extent,
|
||||
h5part_int64_t k,
|
||||
h5part_int64_t z_extent
|
||||
) {
|
||||
return i + j*x_extent + k*x_extent*y_extent;
|
||||
}
|
||||
|
||||
static int
|
||||
_define_3dlayout (
|
||||
H5PartFile *f,
|
||||
h5part_int64_t *dims
|
||||
) {
|
||||
|
||||
|
||||
herr_t herr = H5BlockDefine3DFieldLayout ( f,
|
||||
0, dims[0]-1,
|
||||
0, dims[1]-1,
|
||||
0, dims[2]-1 );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
_read3d_scalar (
|
||||
H5PartFile *f,
|
||||
const char *name,
|
||||
h5part_int64_t *dims
|
||||
|
||||
) {
|
||||
h5part_float64_t *data;
|
||||
int i, j, k, idx;
|
||||
|
||||
data = (h5part_float64_t*) malloc (
|
||||
dims[0] * dims[1] * dims[2] * sizeof(*data) );
|
||||
|
||||
herr_t herr = H5Block3dReadScalarField ( f, name, data );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
herr = H5BlockDefine3DFieldLayout ( f,
|
||||
1, 3,
|
||||
1, 4,
|
||||
0, 4 );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
herr = H5Block3dReadScalarField ( f, name, data );
|
||||
if ( herr < 0 ) return -1;
|
||||
for ( i = 0; i < 3; i++ ) {
|
||||
for ( j = 0; j < 4; j++ ) {
|
||||
printf ("(%d,%d,0): ", i, j );
|
||||
for ( k = 0; k < 5; k++ ) {
|
||||
idx = calc_index_KJI ( i, 3, j, 4, k, 5 );
|
||||
printf ( "%.0f ", *(data+idx) );
|
||||
}
|
||||
printf ( "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
herr = H5BlockDefine3DFieldLayout ( f,
|
||||
0, dims[0]-1,
|
||||
0, dims[1]-1,
|
||||
0, dims[2]-1 );
|
||||
if ( herr < 0 ) return -1;
|
||||
herr = H5Block3dReadScalarField ( f, name, data );
|
||||
if ( herr < 0 ) return -1;
|
||||
for ( i = 0; i < dims[0]; i++ ) {
|
||||
for ( j = 0; j < dims[1]; j++ ) {
|
||||
printf ("(%d,%d,0): ", i, j );
|
||||
for ( k = 0; k < dims[2]; k++ ) {
|
||||
idx = calc_index_KJI ( i, dims[0], j, dims[1], k, dims[2] );
|
||||
printf ( "%.0f ", *(data+idx) );
|
||||
}
|
||||
printf ( "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_read3d_3d_vector (
|
||||
H5PartFile *f,
|
||||
const char *name,
|
||||
h5part_int64_t *dims
|
||||
|
||||
) {
|
||||
h5part_float64_t *x_data;
|
||||
h5part_float64_t *y_data;
|
||||
h5part_float64_t *z_data;
|
||||
|
||||
x_data = (h5part_float64_t*) malloc (
|
||||
dims[0] * dims[1] * dims[2] * sizeof(*x_data) );
|
||||
y_data = (h5part_float64_t*) malloc (
|
||||
dims[0] * dims[1] * dims[2] * sizeof(*y_data) );
|
||||
z_data = (h5part_float64_t*) malloc (
|
||||
dims[0] * dims[1] * dims[2] * sizeof(*z_data) );
|
||||
|
||||
herr_t herr = H5Block3dRead3dVectorField ( f, name,
|
||||
x_data, y_data, z_data );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_read_field (
|
||||
H5PartFile *f,
|
||||
h5part_int64_t idx
|
||||
) {
|
||||
|
||||
|
||||
char name[256];
|
||||
h5part_int64_t grid_rank;
|
||||
h5part_int64_t grid_dims[16];
|
||||
h5part_int64_t field_dims;
|
||||
|
||||
herr_t herr = H5BlockGetFieldInfo (
|
||||
f,
|
||||
idx,
|
||||
name, sizeof(name),
|
||||
&grid_rank,
|
||||
grid_dims,
|
||||
&field_dims );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
printf ( "Field #%lld has name \"%s\"\n", (long long) idx, name );
|
||||
|
||||
switch ( grid_rank ) {
|
||||
case 3:
|
||||
printf ( "\tGrid dimension of \"%s\" is 3\n", name );
|
||||
printf ( "\tThe dimesion sizes are: (%lld, %lld, %lld)\n",
|
||||
(long long)grid_dims[0], (long long)grid_dims[1], (long long)grid_dims[2] );
|
||||
if ( field_dims == 1 ) {
|
||||
printf ( "\tField data are scalar\n" );
|
||||
} else {
|
||||
printf ( "\tField data are %lld vectors\n",
|
||||
(long long)field_dims );
|
||||
}
|
||||
_define_3dlayout ( f, grid_dims );
|
||||
if ( field_dims == 1 ) {
|
||||
_read3d_scalar ( f, name, grid_dims );
|
||||
} else if ( field_dims == 3 ) {
|
||||
_read3d_3d_vector ( f, name, grid_dims );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf ( "unknown grid rank %lld!!!\n", (long long)grid_rank );
|
||||
}
|
||||
#if 0
|
||||
for ( i = 0; i < i_dims; i++ ) {
|
||||
for ( j = 0; j < j_dims; j++ ) {
|
||||
for ( k = 0; k < k_dims; k++ ) {
|
||||
h5part_int64_t idx;
|
||||
idx = k + j*k_dims + i*k_dims*j_dims;
|
||||
|
||||
if ( *(data+idx) != i + 10*j + 100*k ) {
|
||||
printf ( "Block data error!\n" );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free ( data );
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
ReadFile (
|
||||
const char *fn
|
||||
) {
|
||||
|
||||
H5PartFile *f;
|
||||
h5part_int64_t herr;
|
||||
|
||||
h5part_int64_t timestep;
|
||||
h5part_int64_t timesteps;
|
||||
|
||||
h5part_int64_t i, n;
|
||||
|
||||
|
||||
printf ("Opening file %s\n", fn );
|
||||
|
||||
f = H5PartOpenFile ( fn, H5PART_READ );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
timesteps = H5PartGetNumSteps ( f );
|
||||
|
||||
printf ( "Timesteps = %lld\n", (long long)timesteps );
|
||||
printf ( "\n===============================\n" );
|
||||
|
||||
for ( timestep = 0; timestep < timesteps; timestep++) {
|
||||
herr = H5PartSetStep ( f, timestep );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
n = H5BlockGetNumFields ( f );
|
||||
if ( n < 0 ) return -1;
|
||||
printf ( "Number of fields in time-step #%lld: %lld \n",
|
||||
(long long)timestep, (long long)n );
|
||||
|
||||
for ( i = 0; i < n; i++ ) {
|
||||
_read_field ( f, i );
|
||||
|
||||
}
|
||||
}
|
||||
return H5PartCloseFile ( f );
|
||||
}
|
||||
|
||||
int
|
||||
WriteFile (
|
||||
const char *fn
|
||||
) {
|
||||
|
||||
H5PartFile *f;
|
||||
h5part_int64_t i, j, k;
|
||||
int timestep;
|
||||
int timesteps = 5;
|
||||
h5part_int64_t herr;
|
||||
h5part_float64_t *data;
|
||||
h5part_int64_t i_dims, j_dims, k_dims;
|
||||
|
||||
printf ("Opening file \"%s\" for writing\n", fn );
|
||||
|
||||
i_dims = 4;
|
||||
j_dims = 6;
|
||||
k_dims = 8;
|
||||
|
||||
data = (h5part_float64_t*) malloc (
|
||||
i_dims * j_dims * k_dims * sizeof(*data) );
|
||||
|
||||
|
||||
f = H5PartOpenFile ( fn, H5PART_WRITE );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
for ( timestep = 0; timestep < timesteps; timestep++){
|
||||
herr = H5PartSetStep ( f, timestep );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
printf ( "Write Step %d\n", timestep );
|
||||
|
||||
for ( i = 0; i < i_dims; i++ ) {
|
||||
for ( j = 0; j < j_dims; j++ ) {
|
||||
for ( k = 0; k < k_dims; k++ ) {
|
||||
h5part_int64_t idx;
|
||||
idx = calc_index_KJI ( i, i_dims, j, j_dims, k, k_dims );
|
||||
|
||||
*(data + idx) = k+ 10*j + 100*i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
herr = H5BlockDefine3DFieldLayout ( f,
|
||||
0, i_dims-1,
|
||||
0, j_dims-1,
|
||||
0, k_dims-1 );
|
||||
if ( herr < 0 ) return -1;
|
||||
herr = H5Block3dWriteScalarField ( f, "scalar", data );
|
||||
if ( herr < 0 ) return -1;
|
||||
herr = H5Block3dWrite3dVectorField ( f, "3dVector",
|
||||
data, data, data );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
}
|
||||
free ( data );
|
||||
return H5PartCloseFile ( f );
|
||||
}
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char **argv
|
||||
|
||||
) {
|
||||
|
||||
char *fn;
|
||||
char dstr[]="testfile.h5";
|
||||
|
||||
if ( argc > 1 )
|
||||
fn = argv[1];
|
||||
else
|
||||
fn = dstr;
|
||||
|
||||
H5PartSetVerbosityLevel ( 10 );
|
||||
|
||||
if ( WriteFile ( fn ) < 0 ){
|
||||
printf (" Failed to write file %s\n", fn );
|
||||
exit ( 2 );
|
||||
}
|
||||
|
||||
if ( ReadFile ( fn ) < 0 ){
|
||||
printf ("Failed to read file %s\n", fn );
|
||||
exit ( 2 );
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <hdf5.h>
|
||||
#include "H5Part.h"
|
||||
#include "H5Block.h"
|
||||
|
||||
|
||||
static h5part_int64_t
|
||||
calc_index_KJI (
|
||||
h5part_int64_t i,
|
||||
h5part_int64_t x_extent,
|
||||
h5part_int64_t j,
|
||||
h5part_int64_t y_extent,
|
||||
h5part_int64_t k,
|
||||
h5part_int64_t z_extent
|
||||
) {
|
||||
return i + j*x_extent + k*x_extent*y_extent;
|
||||
}
|
||||
|
||||
int
|
||||
WriteFile (
|
||||
const char *fn,
|
||||
h5part_int64_t i_dims,
|
||||
h5part_int64_t j_dims,
|
||||
h5part_int64_t k_dims
|
||||
) {
|
||||
|
||||
H5PartFile *f;
|
||||
h5part_int64_t i, j, k;
|
||||
int timestep;
|
||||
int timesteps = 1;
|
||||
h5part_int64_t herr;
|
||||
h5part_float64_t *data;
|
||||
|
||||
printf ("Opening file \"%s\" for writing\n", fn );
|
||||
|
||||
data = (h5part_float64_t*) malloc (
|
||||
i_dims * j_dims * k_dims * sizeof(*data) );
|
||||
|
||||
|
||||
f = H5PartOpenFile ( fn, H5PART_WRITE );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
for ( timestep = 0; timestep < timesteps; timestep++){
|
||||
herr = H5PartSetStep ( f, timestep );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
printf ( "Write Step %d\n", timestep );
|
||||
|
||||
for ( i = 0; i < i_dims; i++ ) {
|
||||
for ( j = 0; j < j_dims; j++ ) {
|
||||
for ( k = 0; k < k_dims; k++ ) {
|
||||
h5part_int64_t idx;
|
||||
idx = calc_index_KJI ( i, i_dims, j, j_dims, k, k_dims );
|
||||
|
||||
*(data + idx) = k+ 1000*j + 100000*i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
herr = H5BlockDefine3DFieldLayout ( f,
|
||||
0, i_dims-1,
|
||||
0, j_dims-1,
|
||||
0, k_dims-1 );
|
||||
if ( herr < 0 ) return -1;
|
||||
herr = H5Block3dWriteScalarField ( f, "scalar", data );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
}
|
||||
free ( data );
|
||||
return H5PartCloseFile ( f );
|
||||
}
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char **argv
|
||||
|
||||
) {
|
||||
|
||||
char *fn = "blockfile1.h5";
|
||||
|
||||
H5PartSetVerbosityLevel ( 10 );
|
||||
|
||||
if ( WriteFile ( fn, 64, 64, 512 ) < 0 ){
|
||||
printf (" Failed to write file %s\n", fn );
|
||||
exit ( 2 );
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <hdf5.h>
|
||||
#include "H5Part.h"
|
||||
#include "H5Block.h"
|
||||
#include "H5BlockTypes.h"
|
||||
|
||||
struct H5BlockPartition Layout[1] = {
|
||||
{ 0, 63, 0, 63, 0, 511 }
|
||||
};
|
||||
|
||||
static h5part_int64_t
|
||||
_calc_index_KJI (
|
||||
int myproc,
|
||||
h5part_int64_t i,
|
||||
h5part_int64_t j,
|
||||
h5part_int64_t k
|
||||
) {
|
||||
h5part_int64_t i_dims = Layout[myproc].i_end - Layout[myproc].i_start + 1;
|
||||
h5part_int64_t j_dims = Layout[myproc].j_end - Layout[myproc].j_start + 1;
|
||||
|
||||
return i + j*i_dims + k*i_dims*j_dims;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static h5part_int64_t
|
||||
_write_file (
|
||||
H5PartFile *f,
|
||||
int myproc,
|
||||
int nprocs
|
||||
){
|
||||
|
||||
h5part_int64_t i, j, k, idx;
|
||||
h5part_int64_t herr;
|
||||
h5part_float64_t *data;
|
||||
h5part_int64_t i_dims = Layout[myproc].i_end - Layout[myproc].i_start + 1;
|
||||
h5part_int64_t j_dims = Layout[myproc].j_end - Layout[myproc].j_start + 1;
|
||||
h5part_int64_t k_dims = Layout[myproc].k_end - Layout[myproc].k_start + 1;
|
||||
|
||||
|
||||
printf ( "Writing Step #%lld\n", (long long)f->timestep );
|
||||
|
||||
data = malloc ( i_dims * j_dims * k_dims * sizeof ( *data ) );
|
||||
for ( i = 0; i < i_dims; i++ ) {
|
||||
for ( j = 0; j < j_dims; j++ ) {
|
||||
for ( k = 0; k < k_dims; k++ ) {
|
||||
idx = _calc_index_KJI ( myproc, i, j, k );
|
||||
*(data + idx) = k
|
||||
+ 1000*j
|
||||
+ 100000*i
|
||||
+ 10000000*myproc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
herr = H5BlockDefine3DFieldLayout (
|
||||
f,
|
||||
Layout[myproc].i_start, Layout[myproc].i_end,
|
||||
Layout[myproc].j_start, Layout[myproc].j_end,
|
||||
Layout[myproc].k_start, Layout[myproc].k_end );
|
||||
if ( herr < 0 ) return herr;
|
||||
|
||||
herr = H5Block3dWriteScalarField ( f, "TestField", data );
|
||||
if ( herr < 0 ) return herr;
|
||||
|
||||
free ( data );
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char **argv
|
||||
) {
|
||||
char *fname = "blockfile1.h5";
|
||||
int timestep = 0;
|
||||
int myproc;
|
||||
int nprocs;
|
||||
h5part_int64_t herr;
|
||||
H5PartFile *f;
|
||||
MPI_Comm comm = MPI_COMM_WORLD;
|
||||
|
||||
MPI_Init( &argc, &argv );
|
||||
MPI_Comm_size ( comm, &nprocs );
|
||||
MPI_Comm_rank( comm, &myproc );
|
||||
|
||||
if ( nprocs != 1 ) {
|
||||
printf ( "Run this test with 1 processor!" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf ("PROC[%d]: Open file \"%s\" for writing ...\n", myproc, fname );
|
||||
|
||||
f = H5PartOpenFileParallel ( fname, H5PART_WRITE, comm );
|
||||
if ( f == NULL ) return -1;
|
||||
|
||||
herr = H5PartSetStep ( f, timestep );
|
||||
if ( herr < 0 ) return herr;
|
||||
|
||||
|
||||
H5PartSetVerbosityLevel ( 40 );
|
||||
|
||||
if ( _write_file ( f, myproc, nprocs ) < 0 ) {
|
||||
printf ("Failed to write file \"%s\"\n", fname );
|
||||
return 2;
|
||||
}
|
||||
|
||||
herr = H5BlockWriteFieldAttribString (
|
||||
f,
|
||||
"TestField",
|
||||
"TestString",
|
||||
"42" );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
h5part_int64_t ival[1] = { 42 };
|
||||
h5part_float64_t rval[1] = { 42.0 };
|
||||
herr = H5BlockWriteFieldAttrib (
|
||||
f,
|
||||
"TestField",
|
||||
"TestInt64",
|
||||
H5PART_INT64,
|
||||
ival, 1 );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
herr = H5BlockWriteFieldAttrib (
|
||||
f,
|
||||
"TestField",
|
||||
"TestFloat64",
|
||||
H5PART_FLOAT64,
|
||||
rval, 1 );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
|
||||
herr = H5PartCloseFile ( f );
|
||||
if ( herr < 0 ) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user