[MOAB-dev] r1992 - in MOAB/trunk: parallel test/h5file
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Tue Jul 8 10:33:59 CDT 2008
Author: kraftche
Date: 2008-07-08 10:33:58 -0500 (Tue, 08 Jul 2008)
New Revision: 1992
Removed:
MOAB/trunk/test/h5file/varlen_ll.cpp
Modified:
MOAB/trunk/parallel/parallel_hdf5_test.cc
MOAB/trunk/test/h5file/Makefile.am
Log:
move test for I/O of var-len tags into new parallel hdf5 tests
Modified: MOAB/trunk/parallel/parallel_hdf5_test.cc
===================================================================
--- MOAB/trunk/parallel/parallel_hdf5_test.cc 2008-07-08 15:24:09 UTC (rev 1991)
+++ MOAB/trunk/parallel/parallel_hdf5_test.cc 2008-07-08 15:33:58 UTC (rev 1992)
@@ -4,6 +4,7 @@
#include "MBParallelComm.hpp"
#include "MBTagConventions.hpp"
#include "MBCN.hpp"
+#include "MBParallelConventions.h"
#include <iostream>
#include <mpi.h>
@@ -24,8 +25,8 @@
void check_identical_mesh( MBInterface& moab1, MBInterface& moab2 );
void test_write_elements();
-
void test_write_shared_sets();
+void test_var_length_parallel();
bool KeepTmpFiles = false;
@@ -44,6 +45,7 @@
int result = 0;
result += RUN_TEST( test_write_elements );
result += RUN_TEST( test_write_shared_sets );
+ result += RUN_TEST( test_var_length_parallel );
MPI_Finalize();
return result;
@@ -288,7 +290,119 @@
CHECK( check_sets_sizes( moab2, *i, moab, tmpents.front() ) );
}
}
-
+
+
+void test_var_length_parallel()
+{
+ MBRange::const_iterator i;
+ MBErrorCode rval;
+ MBCore moab;
+ MBInterface &mb = moab;
+ MBRange verts;
+ MBTag vartag;
+ const char* filename = "var-len-para.h5m";
+ const char* tagname = "ParVar";
-
+ // If this tag doesn't exist, writer will fail
+ MBTag junk_tag;
+ mb.tag_create( PARALLEL_GID_TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, junk_tag, 0 );
+
+ int numproc, rank;
+ MPI_Comm_size( MPI_COMM_WORLD, &numproc );
+ MPI_Comm_rank( MPI_COMM_WORLD, &rank );
+ // Create N+1 vertices on each processor, where N is the rank
+ std::vector<double> coords( 3*rank+3, (double)rank );
+ rval = mb.create_vertices( &coords[0], rank+1, verts );
+ CHECK_ERR(rval);
+
+ // Create a var-len tag
+ rval = mb.tag_create_variable_length( tagname, MB_TAG_DENSE, MB_TYPE_INTEGER, vartag );
+ CHECK_ERR(rval);
+
+ // Write data on each vertex:
+ // { n, rank, rank+1, ..., rank+n-1 } where n >= 1
+ std::vector<int> data;
+ rval = MB_SUCCESS;
+ for (i = verts.begin(); i != verts.end(); ++i) {
+ MBEntityHandle h = *i;
+ const int n = h % 7 + 1;
+ data.resize( n+1 );
+ data[0] = n;
+ for (int j = 0; j < n; ++j)
+ data[j+1] = rank + j;
+ const int s = (n + 1) * sizeof(int);
+ const void* ptrarr[] = { &data[0] };
+ MBErrorCode tmperr = mb.tag_set_data( vartag, &h, 1, ptrarr, &s );
+ if (MB_SUCCESS != tmperr)
+ rval = tmperr;
+ }
+ CHECK_ERR(rval);
+
+ // Write file
+ rval = mb.write_file( filename, "MOAB", "PARALLEL=FORMAT" );
+ CHECK_ERR(rval);
+
+ // Read file. We only reset and re-read the file on the
+ // root processsor. All other processors keep the pre-write
+ // mesh. This allows many of the tests to be run on all
+ // processors. Running the tests on the pre-write mesh on
+ // non-root processors allows us to verify that any problems
+ // are due to the file API rather than some other bug.
+ MBErrorCode rval2 = rval = MB_SUCCESS;
+ if (!rank) {
+ moab.~MBCore();
+ new (&moab) MBCore;
+ rval = mb.load_mesh( filename );
+ if (!KeepTmpFiles)
+ remove( filename );
+ rval2 = mb.tag_get_handle( tagname, vartag );
+ }
+ CHECK_ERR(rval);
+ CHECK_ERR(rval2);
+
+ // Check that tag is correct
+ int tag_size;
+ rval = mb.tag_get_size( vartag, tag_size );
+ CHECK_EQUAL( MB_VARIABLE_DATA_LENGTH, rval );
+ MBTagType storage;
+ rval = mb.tag_get_type( vartag, storage );
+ CHECK_EQUAL( MB_TAG_DENSE, storage );
+ MBDataType type;
+ rval = mb.tag_get_data_type( vartag, type);
+ CHECK_EQUAL( MB_TYPE_INTEGER, type );
+
+ // get vertices
+ verts.clear();
+ rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
+ CHECK_ERR(rval);
+
+ // Check consistency of tag data on each vertex
+ // and count the number of vertices for each rank.
+ std::vector<int> vtx_counts( numproc, 0 );
+ for (i = verts.begin(); i != verts.end(); ++i) {
+ MBEntityHandle h = *i;
+ int size = -1;
+ const void* ptrarr[1] = { 0 };
+ rval = mb.tag_get_data( vartag, &h, 1, ptrarr, &size );
+ size /= sizeof(int);
+ CHECK_ERR( rval );
+ const int* data = reinterpret_cast<const int*>(ptrarr[0]);
+ CHECK( size >= 2 );
+ CHECK( NULL != data );
+ CHECK_EQUAL( size-1, data[0] );
+ CHECK( data[1] >= 0 && data[1] < numproc );
+ ++vtx_counts[data[1]];
+ for (int j = 1; j < size-1; ++j)
+ CHECK_EQUAL( data[1]+j, data[1+j] );
+ }
+
+ // Check number of vertices for each rank
+ for (int j = 0; j < numproc; ++j) {
+ // Only root should have data for other processors.
+ if (rank == 0 || rank == j)
+ CHECK_EQUAL( j+1, vtx_counts[j] );
+ else
+ CHECK_EQUAL( 0, vtx_counts[j] );
+ }
+}
Modified: MOAB/trunk/test/h5file/Makefile.am
===================================================================
--- MOAB/trunk/test/h5file/Makefile.am 2008-07-08 15:24:09 UTC (rev 1991)
+++ MOAB/trunk/test/h5file/Makefile.am 2008-07-08 15:33:58 UTC (rev 1992)
@@ -1,7 +1,7 @@
DEFS = $(DEFINES)
INCLUDES += -I$(top_srcdir) -I$(top_srcdir)/mhdf/include -I$(top_builddir)
check_PROGRAMS = h5test h5legacy h5varlen h5sets_test
-parallel_programs = varlen_ll mhdf_parallel
+parallel_programs = mhdf_parallel
if PARALLEL_HDF5
check_PROGRAMS += $(parallel_programs)
@@ -14,6 +14,5 @@
h5test_SOURCES = h5file_test.cpp
h5legacy_SOURCES = h5legacy.cpp
h5varlen_SOURCES = h5varlen.cpp
-parallel_SOURCES = parallel.cpp
-varlen_ll_SOURCES = varlen_ll.cpp
+mhdf_parallel_SOURCES = mhdf_parallel.c
h5sets_test_SOURCES = h5sets_test.cpp
Deleted: MOAB/trunk/test/h5file/varlen_ll.cpp
===================================================================
--- MOAB/trunk/test/h5file/varlen_ll.cpp 2008-07-08 15:24:09 UTC (rev 1991)
+++ MOAB/trunk/test/h5file/varlen_ll.cpp 2008-07-08 15:33:58 UTC (rev 1992)
@@ -1,162 +0,0 @@
-/**\file varlen_ll.cpp
- * \brief Test HDF5 parallel I/O of variable-length tag data.
- * \author Jason Kraftcheck <kraftche at cae.wisc.edu>
- */
-
-#include "MBCore.hpp"
-#include "TestUtil.hpp"
-#include "MBParallelConventions.h"
-
-#include <mpi.h>
-
-bool keep_files = false; // controllable with -k flag
-bool wait_on_start = false; // start all procs and wait for input on root node
-
-void test_var_length_parallel();
-
-int main(int argc, char* argv[])
-{
- MPI_Init( &argc, &argv );
-
- for (int i = 1; i < argc; ++i) {
- if (!strcmp(argv[i], "-k"))
- keep_files = true;
- else if (!strcmp(argv[i], "-w"))
- wait_on_start = true;
- else {
- fprintf( stderr, "Usage: %s [-k] [-w]\n", argv[0] );
- abort();
- }
- }
-
- if (wait_on_start) {
- int rank;
- MPI_Comm_rank( MPI_COMM_WORLD, &rank );
- if (0 == rank) {
- puts( "Press <enter> to begin: ");
- fflush( stdout );
- getchar();
- }
- MPI_Barrier(MPI_COMM_WORLD);
- }
-
- int err_count = 0;
- err_count += RUN_TEST( test_var_length_parallel );
- return err_count;
-}
-
-
-void test_var_length_parallel()
-{
- MBRange::const_iterator i;
- MBErrorCode rval;
- MBCore moab;
- MBInterface &mb = moab;
- MBRange verts;
- MBTag vartag;
- const char* filename = "var-len-para.h5m";
- const char* tagname = "ParVar";
-
- // If this tag doesn't exist, writer will fail
- MBTag junk_tag;
- mb.tag_create( PARALLEL_GID_TAG_NAME, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, junk_tag, 0 );
-
- int numproc, rank;
- MPI_Comm_size( MPI_COMM_WORLD, &numproc );
- MPI_Comm_rank( MPI_COMM_WORLD, &rank );
-
- // Create N+1 vertices on each processor, where N is the rank
- std::vector<double> coords( 3*rank+3, (double)rank );
- rval = mb.create_vertices( &coords[0], rank+1, verts );
- CHECK_ERR(rval);
-
- // Create a var-len tag
- rval = mb.tag_create_variable_length( tagname, MB_TAG_DENSE, MB_TYPE_INTEGER, vartag );
- CHECK_ERR(rval);
-
- // Write data on each vertex:
- // { n, rank, rank+1, ..., rank+n-1 } where n >= 1
- std::vector<int> data;
- rval = MB_SUCCESS;
- for (i = verts.begin(); i != verts.end(); ++i) {
- MBEntityHandle h = *i;
- const int n = h % 7 + 1;
- data.resize( n+1 );
- data[0] = n;
- for (int j = 0; j < n; ++j)
- data[j+1] = rank + j;
- const int s = (n + 1) * sizeof(int);
- const void* ptrarr[] = { &data[0] };
- MBErrorCode tmperr = mb.tag_set_data( vartag, &h, 1, ptrarr, &s );
- if (MB_SUCCESS != tmperr)
- rval = tmperr;
- }
- CHECK_ERR(rval);
-
- // Write file
- rval = mb.write_file( filename, "MOAB", "PARALLEL=FORMAT" );
- CHECK_ERR(rval);
-
- // Read file. We only reset and re-read the file on the
- // root processsor. All other processors keep the pre-write
- // mesh. This allows many of the tests to be run on all
- // processors. Running the tests on the pre-write mesh on
- // non-root processors allows us to verify that any problems
- // are due to the file API rather than some other bug.
- MBErrorCode rval2 = rval = MB_SUCCESS;
- if (!rank) {
- moab.~MBCore();
- new (&moab) MBCore;
- rval = mb.load_mesh( filename );
- if (!keep_files)
- remove( filename );
- rval2 = mb.tag_get_handle( tagname, vartag );
- }
- CHECK_ERR(rval);
- CHECK_ERR(rval2);
-
- // Check that tag is correct
- int tag_size;
- rval = mb.tag_get_size( vartag, tag_size );
- CHECK_EQUAL( MB_VARIABLE_DATA_LENGTH, rval );
- MBTagType storage;
- rval = mb.tag_get_type( vartag, storage );
- CHECK_EQUAL( MB_TAG_DENSE, storage );
- MBDataType type;
- rval = mb.tag_get_data_type( vartag, type);
- CHECK_EQUAL( MB_TYPE_INTEGER, type );
-
- // get vertices
- verts.clear();
- rval = mb.get_entities_by_type( 0, MBVERTEX, verts );
- CHECK_ERR(rval);
-
- // Check consistency of tag data on each vertex
- // and count the number of vertices for each rank.
- std::vector<int> vtx_counts( numproc, 0 );
- for (i = verts.begin(); i != verts.end(); ++i) {
- MBEntityHandle h = *i;
- int size = -1;
- const void* ptrarr[1] = { 0 };
- rval = mb.tag_get_data( vartag, &h, 1, ptrarr, &size );
- size /= sizeof(int);
- CHECK_ERR( rval );
- const int* data = reinterpret_cast<const int*>(ptrarr[0]);
- CHECK( size >= 2 );
- CHECK( NULL != data );
- CHECK_EQUAL( size-1, data[0] );
- CHECK( data[1] >= 0 && data[1] < numproc );
- ++vtx_counts[data[1]];
- for (int j = 1; j < size-1; ++j)
- CHECK_EQUAL( data[1]+j, data[1+j] );
- }
-
- // Check number of vertices for each rank
- for (int j = 0; j < numproc; ++j) {
- // Only root should have data for other processors.
- if (rank == 0 || rank == j)
- CHECK_EQUAL( j+1, vtx_counts[j] );
- else
- CHECK_EQUAL( 0, vtx_counts[j] );
- }
-}
More information about the moab-dev
mailing list