static const char help[] = "Simple MOAB driver.\n"; #include "Exception.hh" #include "MBCore.hpp" #include "MBReadUtilIface.hpp" #include "MBParallelComm.hpp" #include "MBParallelConventions.h" #include "petscdmmoab.h" extern "C" { #include "petsc.h" } #include #include #include using namespace moab; using namespace std; int main(int argc, char** argv) { if (argc < 2) { EXCEPT("File name missing."); } PetscErrorCode ierr; moab::ErrorCode merr; PetscInitialize(&argc, &argv, (char*) 0, help); int rank; MPI_Comm_rank(PETSC_COMM_WORLD, &rank); int nprocs; MPI_Comm_size(PETSC_COMM_WORLD, &nprocs); // initialize MOAB Interface* mbint = new moab::Core; if (mbint == NULL) { EXCEPT("Failed to create MOAB core."); return -1; } ParallelComm* pcomm = new ParallelComm(mbint, PETSC_COMM_WORLD); if (pcomm == NULL) { EXCEPT("Failed to create MOAB ParallelComm."); return -1; } ostringstream ost; ost << "PARALLEL=READ_PART;" << "PARTITION=PARALLEL_PARTITION;" << "PARALLEL_RESOLVE_SHARED_ENTS"; string options = ost.str(); // load the file string file_name(argv[1]); if (MB_SUCCESS != mbint->load_file(file_name.c_str(), 0, options.c_str())) { EXCEPT("Cannot load MOAB file '" + file_name + "'."); return -1; } int my_count; vector rbuf(nprocs); Range range; // hexes if (MB_SUCCESS != mbint->get_entities_by_type(0, MBHEX, range)) { EXCEPT("get_entities_by_type failed."); return -1; } my_count = (int)range.size(); MPI_Gather(&my_count, 1, MPI_INT, &rbuf[0], 1, MPI_INT, 0, PETSC_COMM_WORLD); if (rank == 0) { cout << "# hexes :"; for (size_t p = 0; p < rbuf.size(); ++p) { cout << "\t" << rbuf[p]; } cout << endl; } range.clear(); // prisms if (MB_SUCCESS != mbint->get_entities_by_type(0, MBPRISM, range)) { EXCEPT("get_entities_by_type failed."); return -1; } my_count = (int)range.size(); MPI_Gather(&my_count, 1, MPI_INT, &rbuf[0], 1, MPI_INT, 0, PETSC_COMM_WORLD); if (rank == 0) { cout << "# prisms:"; for (size_t p = 0; p < rbuf.size(); ++p) { cout << "\t" << rbuf[p]; } cout << endl; } range.clear(); // vertexes Range verts; if (MB_SUCCESS != mbint->get_entities_by_type(0, MBVERTEX, verts)) { EXCEPT("get_entities_by_type failed."); return -1; } my_count = (int)verts.size(); MPI_Gather(&my_count, 1, MPI_INT, &rbuf[0], 1, MPI_INT, 0, PETSC_COMM_WORLD); if (rank == 0) { cout << "# vertexes:"; for (size_t p = 0; p < rbuf.size(); ++p) { cout << "\t" << rbuf[p]; } cout << endl; } // shared Range shared(verts); if (MB_SUCCESS != pcomm->filter_pstatus(shared, PSTATUS_SHARED, PSTATUS_OR)) { EXCEPT("filter_pstatus failed."); return -1; } my_count = (int)shared.size(); MPI_Gather(&my_count, 1, MPI_INT, &rbuf[0], 1, MPI_INT, 0, PETSC_COMM_WORLD); if (rank == 0) { cout << "# shared:"; for (size_t p = 0; p < rbuf.size(); ++p) { cout << "\t" << rbuf[p]; } cout << endl; } // owned Range owned(verts); if (MB_SUCCESS != pcomm->filter_pstatus(owned, PSTATUS_NOT_OWNED, PSTATUS_NOT)) { EXCEPT("filter_pstatus failed."); return -1; } my_count = (int)owned.size(); MPI_Gather(&my_count, 1, MPI_INT, &rbuf[0], 1, MPI_INT, 0, PETSC_COMM_WORLD); if (rank == 0) { cout << "# owned:"; for (size_t p = 0; p < rbuf.size(); ++p) { cout << "\t" << rbuf[p]; } cout << endl; } // shared/owned Range showned(shared); if (MB_SUCCESS != pcomm->filter_pstatus(showned, PSTATUS_NOT_OWNED, PSTATUS_NOT)) { EXCEPT("filter_pstatus failed."); return -1; } my_count = (int)showned.size(); MPI_Gather(&my_count, 1, MPI_INT, &rbuf[0], 1, MPI_INT, 0, PETSC_COMM_WORLD); if (rank == 0) { cout << "# shared/owned:"; for (size_t p = 0; p < rbuf.size(); ++p) { cout << "\t" << rbuf[p]; } cout << endl; } ierr = PetscFinalize(); return ierr; }