MOAB: Mesh Oriented datABase  (version 5.2.1)
uber_parallel_test.cpp
Go to the documentation of this file.
00001 #include "moab/ParallelComm.hpp"
00002 #include "MBParallelConventions.h"
00003 #include "ReadParallel.hpp"
00004 #include "moab/FileOptions.hpp"
00005 #include "MBTagConventions.hpp"
00006 #include "moab/Core.hpp"
00007 #include "moab_mpi.h"
00008 #include "TestUtil.hpp"
00009 
00010 #include <iostream>
00011 #include <algorithm>
00012 #include <sstream>
00013 #include <assert.h>
00014 #if !defined( _MSC_VER ) && !defined( __MINGW32__ )
00015 #include <unistd.h>
00016 #endif
00017 
00018 using namespace moab;
00019 
00020 #define CHKERR( a )                                                                                   \
00021     do                                                                                                \
00022     {                                                                                                 \
00023         ErrorCode val = ( a );                                                                        \
00024         if( MB_SUCCESS != val )                                                                       \
00025         {                                                                                             \
00026             std::cerr << "Error code  " << val << " at " << __FILE__ << ":" << __LINE__ << std::endl; \
00027             return val;                                                                               \
00028         }                                                                                             \
00029     } while( false )
00030 
00031 #define PCHECK( A ) \
00032     if( is_any_proc_error( !( A ) ) ) return report_error( __FILE__, __LINE__ )
00033 
00034 ErrorCode report_error( const char* file, int line )
00035 {
00036     std::cerr << "Failure at " << file << ':' << line << std::endl;
00037     return MB_FAILURE;
00038 }
00039 
00040 ErrorCode test_read( const char* filename, const char* option );
00041 
00042 #define RUN_TEST_ARG3( A, B, C ) run_test( &A, #A, B, C )
00043 
00044 int is_any_proc_error( int is_my_error )
00045 {
00046     int result = 0;
00047     int err    = MPI_Allreduce( &is_my_error, &result, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD );
00048     return err || result;
00049 }
00050 
00051 int run_test( ErrorCode ( *func )( const char*, const char* ), const char* func_name, const std::string file_name,
00052               const char* option )
00053 {
00054     ErrorCode result = ( *func )( file_name.c_str(), option );
00055     int is_err       = is_any_proc_error( ( MB_SUCCESS != result ) );
00056     int rank;
00057     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
00058     if( rank == 0 )
00059     {
00060         if( is_err )
00061             std::cout << func_name << " : FAILED!!" << std::endl;
00062         else
00063             std::cout << func_name << " : success" << std::endl;
00064     }
00065 
00066     return is_err;
00067 }
00068 
00069 int main( int argc, char* argv[] )
00070 {
00071     int rank, size;
00072     MPI_Init( &argc, &argv );
00073     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
00074     MPI_Comm_size( MPI_COMM_WORLD, &size );
00075     int num_errors = 0;
00076 
00077     const char* option;
00078     std::string filename, filename2;
00079     if( 1 < argc )
00080         filename = std::string( argv[1] );
00081     else
00082     {
00083         filename  = TestDir + "/64bricks_512hex.h5m";
00084         filename2 = TestDir + "/hex_2048.vtk";
00085     }
00086 #ifdef MOAB_HAVE_HDF5
00087     //=========== read_delete, geom_dimension, resolve_shared
00088     option = "PARALLEL=READ_DELETE;PARTITION=GEOM_DIMENSION;PARTITION_VAL=3;PARTITION_DISTRIBUTE;"
00089              "PARALLEL_RESOLVE_SHARED_ENTS;";
00090     num_errors += RUN_TEST_ARG3( test_read, filename, option );
00091 
00092     //=========== read_delete, material_set, resolve_shared
00093     option = "PARALLEL=READ_DELETE;PARTITION=MATERIAL_SET;PARTITION_DISTRIBUTE;PARALLEL_RESOLVE_"
00094              "SHARED_ENTS;";
00095     num_errors += RUN_TEST_ARG3( test_read, filename, option );
00096 
00097     //=========== bcast_delete, geom_dimension, resolve_shared
00098     option = "PARALLEL=BCAST_DELETE;PARTITION=GEOM_DIMENSION;PARTITION_VAL=3;PARTITION_DISTRIBUTE;"
00099              "PARALLEL_RESOLVE_SHARED_ENTS;";
00100     num_errors += RUN_TEST_ARG3( test_read, filename, option );
00101 
00102     //=========== bcast_delete, material_set, resolve_shared
00103     option = "PARALLEL=BCAST_DELETE;PARTITION=MATERIAL_SET;PARTITION_DISTRIBUTE;PARALLEL_RESOLVE_"
00104              "SHARED_ENTS;";
00105     num_errors += RUN_TEST_ARG3( test_read, filename, option );
00106 
00107     //=========== read_delete, geom_dimension, resolve_shared, exch ghost
00108     option = "PARALLEL=READ_DELETE;PARTITION=GEOM_DIMENSION;PARTITION_VAL=3;PARTITION_DISTRIBUTE;"
00109              "PARALLEL_RESOLVE_SHARED_ENTS;PARALLEL_GHOSTS=3.0.1;";
00110     num_errors += RUN_TEST_ARG3( test_read, filename, option );
00111 
00112     //=========== read_delete, material_set, resolve_shared, exch ghost
00113     option = "PARALLEL=READ_DELETE;PARTITION=MATERIAL_SET;PARTITION_DISTRIBUTE;PARALLEL_RESOLVE_"
00114              "SHARED_ENTS;PARALLEL_GHOSTS=3.0.1;";
00115     num_errors += RUN_TEST_ARG3( test_read, filename, option );
00116 
00117     //=========== bcast_delete, geom_dimension, resolve_shared, exch ghost
00118     option = "PARALLEL=BCAST_DELETE;PARTITION=GEOM_DIMENSION;PARTITION_VAL=3;PARTITION_DISTRIBUTE;"
00119              "PARALLEL_RESOLVE_SHARED_ENTS;PARALLEL_GHOSTS=3.0.1;";
00120     num_errors += RUN_TEST_ARG3( test_read, filename, option );
00121 
00122     //=========== bcast_delete, material_set, resolve_shared, exch ghost
00123     option = "PARALLEL=BCAST_DELETE;PARTITION=MATERIAL_SET;PARTITION_DISTRIBUTE;PARALLEL_RESOLVE_"
00124              "SHARED_ENTS;PARALLEL_GHOSTS=3.0.1;";
00125     num_errors += RUN_TEST_ARG3( test_read, filename, option );
00126 #endif
00127     if( filename2.size() )
00128     {
00129         //=========== bcast_delete, trivial, resolve_shared
00130         option = "PARALLEL=BCAST_DELETE;PARTITION=TRIVIAL;PARTITION_DISTRIBUTE;PARALLEL_RESOLVE_"
00131                  "SHARED_ENTS;";
00132         num_errors += RUN_TEST_ARG3( test_read, filename2, option );
00133         //=========== bcast_delete, trivial, resolve_shared + ghosting
00134         option = "PARALLEL=BCAST_DELETE;PARTITION=TRIVIAL;PARTITION_DISTRIBUTE;PARALLEL_RESOLVE_"
00135                  "SHARED_ENTS;PARALLEL_GHOSTS=3.0.1;";
00136         num_errors += RUN_TEST_ARG3( test_read, filename2, option );
00137     }
00138     MPI_Finalize();
00139 
00140     return num_errors;
00141 }
00142 
00143 ErrorCode test_read( const char* filename, const char* option )
00144 {
00145     Core mb_instance;
00146     Interface& moab = mb_instance;
00147     ErrorCode rval;
00148 
00149     rval = moab.load_file( filename, 0, option );CHKERR( rval );
00150 
00151     ParallelComm* pcomm = ParallelComm::get_pcomm( &moab, 0 );
00152 
00153     rval = pcomm->check_all_shared_handles();CHKERR( rval );
00154 
00155     return MB_SUCCESS;
00156 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines