#include "moab/Core.hpp" #include "moab/Interface.hpp" #include "moab/Range.hpp" #include "moab/ParallelComm.hpp" #define PRINT_LAST_ERROR \ if (MB_SUCCESS != result) {\ std::string tmp_str;\ mb->get_last_error(tmp_str);\ std::cout << "Failure; message:" << tmp_str << std::endl;\ delete mb;\ return result;\ } /* ========================================================== */ using namespace moab; using namespace std; // Get MOAB instance Interface* mb = new Core; string test_file_name; int main(int argc, char **argv) { ErrorCode result = MB_SUCCESS; // MPI_Init(&argc, &argv); string options; if (argc > 1){ // user has input a mesh file test_file_name = argv[1]; } options = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS"; // Get the ParallelComm instance ParallelComm* pcomm = new ParallelComm(mb, MPI_COMM_WORLD); int nprocs = pcomm->proc_config().proc_size(); int rank = pcomm->proc_config().proc_rank(); MPI_Comm comm = pcomm->proc_config().proc_comm(); if (rank == 0) cout << "Reading file " << test_file_name << "\n with options: " << options << endl << " on " << nprocs << " processors\n"; result = mb->load_file(test_file_name.c_str(), 0, options.c_str()); PRINT_LAST_ERROR; Range ents; ents.clear(); result = mb->get_entities_by_dimension(0, 3, ents); PRINT_LAST_ERROR; for (moab::Range::iterator it = ents.begin(); it != ents.end(); it++) { EntityHandle ent = *it; HandleVec edges; result = mb->get_adjacencies(&(ent), 1, 1, true, edges); PRINT_LAST_ERROR; } cout << "File loaded on processor " << rank << endl; // Now exchange 1 layer of ghost elements, using vertices as bridge result = pcomm->exchange_ghost_cells(3, // int ghost_dim, 0, // int bridge_dim, 1, //int num_layers, 2, //int addl_ents, true); // bool store_remote_handles); PRINT_LAST_ERROR; // Range shared_ents; // // Get entities shared with all other processors // result = pcomm->get_shared_entities(-1, shared_ents, -1); // PRINT_LAST_ERROR; //if(rank ==0){ cout << "Shared ents on proc " << rank << endl; // shared_ents.print();} /* Range ents; ents.clear(); result = mb->get_entities_by_dimension(0, 3, ents); PRINT_LAST_ERROR; for (moab::Range::iterator it = ents.begin(); it != ents.end(); it++) { EntityHandle ent = *it; HandleVec edges; result = mb->get_adjacencies(&(ent), 1, 1, true, edges); PRINT_LAST_ERROR; }*/ std::string outFile = "ptest.h5m"; char buf [33]; std::string writeOpts = "PARALLEL=WRITE_PART"; // sprintf(buf, "%d", rank); result = mb->write_file(outFile.c_str(), NULL, writeOpts.c_str()); PRINT_LAST_ERROR; if (rank == 0) std::cout << "Wrote " << outFile << std::endl; // outFile.insert(5,buf);//comment for parallel // mb->write_file(outFile.c_str());//comment for parallel }