moab
HelloParMOAB.cpp
Go to the documentation of this file.
00001 
00007 #include "moab/ParallelComm.hpp"
00008 #include "MBParallelConventions.h"
00009 #include "moab/Core.hpp"
00010 #include <iostream>
00011 
00012 using namespace moab;
00013 using namespace std;
00014 
00015 string test_file_name = string(MESH_DIR) + string("/64bricks_512hex_256part.h5m");
00016 
00017 int main(int argc, char **argv)
00018 {
00019   MPI_Init(&argc, &argv);
00020 
00021   string options;
00022 
00023   // Need option handling here for input filename
00024   if (argc > 1){
00025     // user has input a mesh file
00026     test_file_name = argv[1];
00027   }  
00028 
00029   options = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS";
00030 
00031   // Get MOAB instance and read the file with the specified options
00032   Interface* mb = new Core;
00033   if (NULL == mb)
00034     return 1;
00035 
00036   // Get the ParallelComm instance
00037   ParallelComm* pcomm = new ParallelComm(mb, MPI_COMM_WORLD);
00038   int nprocs = pcomm->proc_config().proc_size();
00039   int rank = pcomm->proc_config().proc_rank();
00040   MPI_Comm comm = pcomm->proc_config().proc_comm();
00041 
00042   if (rank == 0)
00043     cout << "Reading file " << test_file_name << "\n  with options: " << options << endl
00044          << " on " << nprocs << " processors\n";
00045 
00046   ErrorCode rval = mb->load_file(test_file_name.c_str(), 0, options.c_str());
00047   if (rval != MB_SUCCESS) {
00048     delete mb;
00049     return 1;
00050   }
00051 
00052   Range shared_ents;
00053   // Get entities shared with all other processors
00054   rval = pcomm->get_shared_entities(-1, shared_ents);
00055   if (rval != MB_SUCCESS) {
00056     delete mb;
00057     return 1;
00058   }
00059 
00060   // Filter shared entities with not not_owned, which means owned
00061   Range owned_entities;
00062   rval = pcomm->filter_pstatus(shared_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &owned_entities);
00063   if (rval != MB_SUCCESS) {
00064     delete mb;
00065     return 1;
00066   }
00067 
00068   unsigned int nums[4] = {0}; // to store the owned entities per dimension
00069   for (int i = 0; i < 4; i++)
00070     nums[i] = (int)owned_entities.num_of_dimension(i);
00071   vector<int> rbuf(nprocs*4, 0);
00072   MPI_Gather(nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, MPI_COMM_WORLD);
00073   // Print the stats gathered:
00074   if (rank == 0) {
00075     for (int i = 0; i < nprocs; i++)
00076       cout << " Shared, owned entities on proc " << i << ": " << rbuf[4*i] << " verts, " <<
00077           rbuf[4*i + 1] << " edges, " << rbuf[4*i + 2] << " faces, " << rbuf[4*i + 3] << " elements" << endl;
00078   }
00079 
00080   // Now exchange 1 layer of ghost elements, using vertices as bridge
00081   // (we could have done this as part of reading process, using the PARALLEL_GHOSTS read option)
00082   rval = pcomm->exchange_ghost_cells(3, // int ghost_dim,
00083                                      0, // int bridge_dim,
00084                                      1, //int num_layers,
00085                                      0, //int addl_ents,
00086                                      true); // bool store_remote_handles);
00087   if (rval != MB_SUCCESS) {
00088     delete mb;
00089     return 1;
00090   }
00091 
00092   // Repeat the reports, after ghost exchange
00093   shared_ents.clear();
00094   owned_entities.clear();
00095   rval = pcomm->get_shared_entities(-1, shared_ents);
00096   if (rval != MB_SUCCESS) {
00097     delete mb;
00098     return 1;
00099   }
00100   rval = pcomm->filter_pstatus(shared_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &owned_entities);
00101   if (rval != MB_SUCCESS) {
00102     delete mb;
00103     return 1;
00104   }
00105 
00106   // find out how many shared entities of each dimension are owned on this processor
00107   for (int i = 0; i < 4; i++)
00108     nums[i] = (int)owned_entities.num_of_dimension(i);
00109 
00110   // gather the statistics on processor 0
00111   MPI_Gather(nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, comm);
00112   if (rank == 0) {
00113     cout << " \n\n After exchanging one ghost layer: \n";
00114     for (int i = 0; i < nprocs; i++) {
00115       cout << " Shared, owned entities on proc " << i << ": " << rbuf[4*i] << " verts, " <<
00116           rbuf[4*i + 1] << " edges, " << rbuf[4*i + 2] << " faces, " << rbuf[4*i + 3] << " elements" << endl;
00117     }
00118   }
00119 
00120   delete mb;
00121 
00122   MPI_Finalize();
00123 
00124   return 0;
00125 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines