[MOAB-dev] commit/MOAB: danwu: Updated parallel unit test for MPAS reader. Gather set is tested separately. Partition result is tested and more cell variable values are checked (can detect some previously fixed bugs). Parallel reading result h5m files are generated differently (trivial partition vs Zoltan partition, mixed_elements vs no_mixed_elements).

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Nov 7 15:59:28 CST 2013


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/3780be5379a6/
Changeset:   3780be5379a6
Branch:      master
User:        danwu
Date:        2013-11-07 22:59:14
Summary:     Updated parallel unit test for MPAS reader. Gather set is tested separately. Partition result is tested and more cell variable values are checked (can detect some previously fixed bugs). Parallel reading result h5m files are generated differently (trivial partition vs Zoltan partition, mixed_elements vs no_mixed_elements).

Affected #:  1 file

diff --git a/test/parallel/mpastrvpart.cpp b/test/parallel/mpastrvpart.cpp
index 24f0b9b..7ff375a 100644
--- a/test/parallel/mpastrvpart.cpp
+++ b/test/parallel/mpastrvpart.cpp
@@ -4,6 +4,9 @@
 #include "moab/ProgOptions.hpp"
 #include "MBParallelConventions.h"
 #include "moab/ReadUtilIface.hpp"
+#include "MBTagConventions.hpp"
+
+#include <sstream>
 
 using namespace moab;
 
@@ -11,26 +14,57 @@ using namespace moab;
 static const char example[] = STRINGIFY(MESHDIR) "/io/mpasx1.642.t.2.nc";
 #endif
 
-void test_read_parallel_mpas_trivial();
-void test_read_parallel_mpas_trivial_no_mixed_elements();
-void test_read_parallel_mpas_rcbzoltan();
-void test_read_parallel_mpas_rcbzoltan_no_mixed_elements();
-void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool test_nb_edges,
-                        int num_cells, bool test_nb_cells, bool mixed_elements);
+void test_read_onevar_trivial();
+void test_read_onevar_trivial_no_mixed_elements();
+#if defined(USE_MPI) && defined(PNETCDF_FILE) && defined(HAVE_ZOLTAN)
+void test_read_onevar_rcbzoltan();
+void test_read_onevar_rcbzoltan_no_mixed_elements();
+#endif
+
+void test_read_mesh_parallel_trivial();
+void test_read_mesh_parallel_trivial_no_mixed_elements();
+#if defined(USE_MPI) && defined(PNETCDF_FILE) && defined(HAVE_ZOLTAN)
+void test_read_mesh_parallel_rcbzoltan();
+void test_read_mesh_parallel_rcbzoltan_no_mixed_elements();
+#endif
+
+void test_gather_onevar_on_rank0();
+void test_gather_onevar_on_rank1();
+
 void test_multiple_loads_of_same_file();
 void test_multiple_loads_of_same_file_no_mixed_elements();
 
-std::string partition_method;
+// Helper functions
+void read_one_cell_var(bool rcbzoltan, bool no_mixed_elements);
+void read_mesh_parallel(bool rcbzoltan, bool no_mixed_elements);
+void gather_one_cell_var(int gather_set_rank);
+void multiple_loads_of_same_file(bool no_mixed_elements);
+
+std::string read_options;
+const double eps = 1e-20;
 
 int main(int argc, char* argv[])
 {
   MPI_Init(&argc, &argv);
   int result = 0;
 
-  result += RUN_TEST(test_read_parallel_mpas_trivial);
-  result += RUN_TEST(test_read_parallel_mpas_trivial_no_mixed_elements);
-  result += RUN_TEST(test_read_parallel_mpas_rcbzoltan);
-  result += RUN_TEST(test_read_parallel_mpas_rcbzoltan_no_mixed_elements);
+  result += RUN_TEST(test_read_onevar_trivial);
+  result += RUN_TEST(test_read_onevar_trivial_no_mixed_elements);
+#if defined(USE_MPI) && defined(PNETCDF_FILE) && defined(HAVE_ZOLTAN)
+  result += RUN_TEST(test_read_onevar_rcbzoltan);
+  result += RUN_TEST(test_read_onevar_rcbzoltan_no_mixed_elements);
+#endif
+
+  result += RUN_TEST(test_read_mesh_parallel_trivial);
+  result += RUN_TEST(test_read_mesh_parallel_trivial_no_mixed_elements);
+#if defined(USE_MPI) && defined(PNETCDF_FILE) && defined(HAVE_ZOLTAN)
+  result += RUN_TEST(test_read_mesh_parallel_rcbzoltan);
+  result += RUN_TEST(test_read_mesh_parallel_rcbzoltan_no_mixed_elements);
+#endif
+
+  result += RUN_TEST(test_gather_onevar_on_rank0);
+  result += RUN_TEST(test_gather_onevar_on_rank1);
+
   result += RUN_TEST(test_multiple_loads_of_same_file);
   result += RUN_TEST(test_multiple_loads_of_same_file_no_mixed_elements);
 
@@ -38,436 +72,553 @@ int main(int argc, char* argv[])
   return result;
 }
 
-void test_read_parallel_mpas_trivial()
+void test_read_onevar_trivial()
+{
+  read_one_cell_var(false, false);
+}
+
+void test_read_onevar_trivial_no_mixed_elements()
+{
+  read_one_cell_var(false, true);
+}
+
+void test_read_onevar_rcbzoltan()
+{
+  read_one_cell_var(true, false);
+}
+
+void test_read_onevar_rcbzoltan_no_mixed_elements()
 {
-  partition_method = std::string(";PARTITION_METHOD=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS");
-  test_read_parallel(1280, true, 1920, true, 642, true, true);
+  read_one_cell_var(true, true);
 }
 
-void test_read_parallel_mpas_trivial_no_mixed_elements()
+void test_read_mesh_parallel_trivial()
 {
-  partition_method = std::string(";PARTITION_METHOD=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS;NO_MIXED_ELEMENTS");
-  test_read_parallel(1280, true, 1920, true, 642, true, false);
+  read_mesh_parallel(false, false);
 }
 
-void test_read_parallel_mpas_rcbzoltan()
+void test_read_mesh_parallel_trivial_no_mixed_elements()
 {
-  partition_method = std::string(";PARTITION_METHOD=RCBZOLTAN;PARALLEL_RESOLVE_SHARED_ENTS");
-  test_read_parallel(1280, false, 1920, false, 642, false, true);
+  read_mesh_parallel(false, true);
 }
 
-void test_read_parallel_mpas_rcbzoltan_no_mixed_elements()
+void test_read_mesh_parallel_rcbzoltan()
 {
-  partition_method = std::string(";PARTITION_METHOD=RCBZOLTAN;PARALLEL_RESOLVE_SHARED_ENTS;NO_MIXED_ELEMENTS");
-  test_read_parallel(1280, false, 1920, false, 642, false, true);
+  read_mesh_parallel(true, false);
 }
 
-void test_read_parallel(int num_verts, bool test_nb_nodes, int num_edges, bool test_nb_edges,
-                        int num_cells, bool test_nb_cells, bool mixed_elements)
+void test_read_mesh_parallel_rcbzoltan_no_mixed_elements()
+{
+  read_mesh_parallel(true, true);
+}
+
+void test_gather_onevar_on_rank0()
+{
+  gather_one_cell_var(0);
+}
+
+void test_gather_onevar_on_rank1()
+{
+  gather_one_cell_var(1);
+}
+
+void test_multiple_loads_of_same_file()
+{
+  multiple_loads_of_same_file(false);
+}
+
+void test_multiple_loads_of_same_file_no_mixed_elements()
+{
+  multiple_loads_of_same_file(true);
+}
+
+// Helper functions
+void read_one_cell_var(bool rcbzoltan, bool no_mixed_elements)
 {
   Core moab;
   Interface& mb = moab;
-  EntityHandle file_set;
-  ErrorCode rval;
-  rval = mb.create_meshset(MESHSET_SET, file_set);
+
+  read_options = "PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL;NO_EDGES;VARIABLE=ke";
+  if (rcbzoltan)
+    read_options = "PARALLEL=READ_PART;PARTITION_METHOD=RCBZOLTAN;NO_EDGES;VARIABLE=ke";
+
+  if (no_mixed_elements)
+    read_options += ";NO_MIXED_ELEMENTS";
+
+  ErrorCode rval = mb.load_file(example, NULL, read_options.c_str());
+  CHECK_ERR(rval);
+
+  // Get local edges
+  Range local_edges;
+  rval = mb.get_entities_by_type(0, MBEDGE, local_edges);
+  CHECK_ERR(rval);
+  CHECK_EQUAL((size_t)0, local_edges.size());
+
+  // Get local cells
+  Range local_cells;
+  rval = mb.get_entities_by_type(0, MBPOLYGON, local_cells);
   CHECK_ERR(rval);
 
-  std::string opt = std::string("PARALLEL=READ_PART") + partition_method;
-  // Create gather set in processor 0
-  opt += std::string(";GATHER_SET=0");
-  rval = mb.load_file(example, &file_set, opt.c_str());
+  Tag gid_tag;
+  rval = mb.tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid_tag, MB_TAG_DENSE);
   CHECK_ERR(rval);
 
+  std::vector<int> gids(local_cells.size());
+  rval = mb.tag_get_data(gid_tag, local_cells, &gids[0]);
+  Range local_cell_gids;
+  std::copy(gids.rbegin(), gids.rend(), range_inserter(local_cell_gids));
+
   ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
   int procs = pcomm->proc_config().proc_size();
   int rank = pcomm->proc_config().proc_rank();
 
-  rval = pcomm->check_all_shared_handles();
-  CHECK_ERR(rval);
+  // Make check runs this test on two processors
+  if (2 == procs) {
+    CHECK_EQUAL((size_t)321, local_cells.size());
+    CHECK_EQUAL((size_t)321, local_cell_gids.size());
 
-  // Get the total # owned verts
-  Range verts;
-  rval = mb.get_entities_by_type(0, MBVERTEX, verts);
-  CHECK_ERR(rval);
+    // Check tag for cell variable ke at timestep 0
+    Tag ke_tag0;
+    rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
+    CHECK_ERR(rval);
+
+    // Check tag for cell variable ke at timestep 1
+    Tag ke_tag1;
+    rval = mb.tag_get_handle("ke1", 1, MB_TYPE_DOUBLE, ke_tag1);
+    CHECK_ERR(rval);
+
+    // Get ke0 and ke1 tag values on 3 local cells
+    EntityHandle cell_ents[] = {local_cells[0], local_cells[160], local_cells[320]};
+    double ke0_val[3];
+    rval = mb.tag_get_data(ke_tag0, cell_ents, 3, ke0_val);
+    CHECK_ERR(rval);
+    double ke1_val[3];
+    rval = mb.tag_get_data(ke_tag1, cell_ents, 3, ke1_val);
+    CHECK_ERR(rval);
 
-  int my_verts_num = verts.size();
-  if (test_nb_nodes && 2 == procs) {
-    if (0 == rank)
-      CHECK_EQUAL(2400, my_verts_num); // Gather set vertices included
-    else if (1 == rank)
-      CHECK_EQUAL(1122, my_verts_num); // Not owned vertices included
+    if (rcbzoltan) {
+      if (no_mixed_elements)
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+      else
+        CHECK_EQUAL((size_t)2, local_cells.psize());
+
+      CHECK_EQUAL((size_t)37, local_cell_gids.psize());
+
+      if (0 == rank) {
+        CHECK_EQUAL(1, (int)local_cell_gids[0]);
+        CHECK_EQUAL(284, (int)local_cell_gids[160]);
+        CHECK_EQUAL(630, (int)local_cell_gids[320]);
+
+        CHECK_REAL_EQUAL(15.001, ke0_val[0], eps);
+        CHECK_REAL_EQUAL(16.284, ke0_val[1], eps);
+        CHECK_REAL_EQUAL(16.630, ke0_val[2], eps);
+        CHECK_REAL_EQUAL(25.001, ke1_val[0], eps);
+        CHECK_REAL_EQUAL(26.284, ke1_val[1], eps);
+        CHECK_REAL_EQUAL(26.630, ke1_val[2], eps);
+      }
+      else if (1 == rank) {
+        CHECK_EQUAL(4, (int)local_cell_gids[0]);
+        CHECK_EQUAL(341, (int)local_cell_gids[160]);
+        CHECK_EQUAL(642, (int)local_cell_gids[320]);
+
+        CHECK_REAL_EQUAL(15.004, ke0_val[0], eps);
+        CHECK_REAL_EQUAL(16.341, ke0_val[1], eps);
+        CHECK_REAL_EQUAL(16.642, ke0_val[2], eps);
+        CHECK_REAL_EQUAL(25.004, ke1_val[0], eps);
+        CHECK_REAL_EQUAL(26.341, ke1_val[1], eps);
+        CHECK_REAL_EQUAL(26.642, ke1_val[2], eps);
+      }
+    }
+    else {
+      CHECK_EQUAL((size_t)1, local_cell_gids.psize());
+
+      if (0 == rank) {
+        if (no_mixed_elements)
+          CHECK_EQUAL((size_t)1, local_cells.psize());
+        else
+          CHECK_EQUAL((size_t)2, local_cells.psize());
+        CHECK_EQUAL(1, (int)local_cell_gids[0]);
+        CHECK_EQUAL(161, (int)local_cell_gids[160]);
+        CHECK_EQUAL(321, (int)local_cell_gids[320]);
+
+        CHECK_REAL_EQUAL(15.001, ke0_val[0], eps);
+        CHECK_REAL_EQUAL(16.161, ke0_val[1], eps);
+        CHECK_REAL_EQUAL(16.321, ke0_val[2], eps);
+        CHECK_REAL_EQUAL(25.001, ke1_val[0], eps);
+        CHECK_REAL_EQUAL(26.161, ke1_val[1], eps);
+        CHECK_REAL_EQUAL(26.321, ke1_val[2], eps);
+      }
+      else if (1 == rank) {
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+        CHECK_EQUAL(322, (int)local_cell_gids[0]);
+        CHECK_EQUAL(482, (int)local_cell_gids[160]);
+        CHECK_EQUAL(642, (int)local_cell_gids[320]);
+
+        CHECK_REAL_EQUAL(16.322, ke0_val[0], eps);
+        CHECK_REAL_EQUAL(16.482, ke0_val[1], eps);
+        CHECK_REAL_EQUAL(16.642, ke0_val[2], eps);
+        CHECK_REAL_EQUAL(26.322, ke1_val[0], eps);
+        CHECK_REAL_EQUAL(26.482, ke1_val[1], eps);
+        CHECK_REAL_EQUAL(26.642, ke1_val[2], eps);
+      }
+    }
   }
+}
 
-  rval = pcomm->filter_pstatus(verts, PSTATUS_NOT_OWNED, PSTATUS_NOT);
+void read_mesh_parallel(bool rcbzoltan, bool no_mixed_elements)
+{
+  Core moab;
+  Interface& mb = moab;
+
+  read_options = "PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS;VARIABLE=";
+  if (rcbzoltan)
+    read_options = "PARALLEL=READ_PART;PARTITION_METHOD=RCBZOLTAN;PARALLEL_RESOLVE_SHARED_ENTS;VARIABLE=";
+
+  if (no_mixed_elements)
+    read_options += ";NO_MIXED_ELEMENTS";
+
+  ErrorCode rval = mb.load_file(example, NULL, read_options.c_str());
   CHECK_ERR(rval);
 
-  my_verts_num = verts.size();
-  if (test_nb_nodes && 2 == procs) {
-    if (0 == rank)
-      CHECK_EQUAL(2400, my_verts_num); // Gather set vertices included
-    else if (1 == rank)
-      CHECK_EQUAL(160, my_verts_num); // Not owned vertices excluded
-  }
+  ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
+  int procs = pcomm->proc_config().proc_size();
+  int rank = pcomm->proc_config().proc_rank();
 
-  // Get the total # owned edges
-  Range edges;
-  rval = mb.get_entities_by_type(0, MBEDGE, edges);
+  rval = pcomm->check_all_shared_handles();
   CHECK_ERR(rval);
 
-  int my_edges_num = edges.size();
-  if (test_nb_edges && 2 == procs) {
-    if (0 == rank)
-      CHECK_EQUAL(3358, my_edges_num); // Gather set edges included
-    else if (1 == rank)
-      CHECK_EQUAL(1444, my_edges_num); // Not owned edges included
+  // Get local vertices
+  Range local_verts;
+  rval = mb.get_entities_by_type(0, MBVERTEX, local_verts);
+  CHECK_ERR(rval);
+
+  int verts_num = local_verts.size();
+  if (2 == procs) {
+    if (rcbzoltan) {
+      if (0 == rank)
+        CHECK_EQUAL(685, verts_num);
+      else if (1 == rank)
+        CHECK_EQUAL(685, verts_num); // Not owned vertices included
+    }
+    else {
+      if (0 == rank)
+        CHECK_EQUAL(1120, verts_num);
+      else if (1 == rank)
+        CHECK_EQUAL(1122, verts_num); // Not owned vertices included
+    }
   }
 
-  rval = pcomm->filter_pstatus(edges, PSTATUS_NOT_OWNED, PSTATUS_NOT);
+  rval = pcomm->filter_pstatus(local_verts, PSTATUS_NOT_OWNED, PSTATUS_NOT);
   CHECK_ERR(rval);
 
-  my_edges_num = edges.size();
-  if (test_nb_edges && 2 == procs) {
-    if (0 == rank)
-      CHECK_EQUAL(3358, my_edges_num); // Gather set edges included
-    else if (1 == rank)
-      CHECK_EQUAL(482, my_edges_num); // Not owned edges excluded
+  verts_num = local_verts.size();
+  if (2 == procs) {
+    if (rcbzoltan) {
+      if (0 == rank)
+        CHECK_EQUAL(685, verts_num);
+      else if (1 == rank)
+        CHECK_EQUAL(595, verts_num); // Not owned vertices excluded
+    }
+    else {
+      if (0 == rank)
+        CHECK_EQUAL(1120, verts_num);
+      else if (1 == rank)
+        CHECK_EQUAL(160, verts_num); // Not owned vertices excluded
+    }
   }
 
-  // Get the total # owned cells
-  Range cells;
-  rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
+  // Get local edges
+  Range local_edges;
+  rval = mb.get_entities_by_type(0, MBEDGE, local_edges);
   CHECK_ERR(rval);
 
-  int my_cells_num = cells.size();
-  if (test_nb_cells && 2 == procs) {
-    if (0 == rank) {
-      CHECK_EQUAL(963, my_cells_num); // Gather set cells included
-      if (mixed_elements)
-        CHECK_EQUAL((size_t)4, cells.psize()); // Gather set cells included
-      else
-        CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells included
+  int edges_num = local_edges.size();
+  if (2 == procs) {
+    if (rcbzoltan) {
+      if (0 == rank)
+        CHECK_EQUAL(1005, edges_num);
+      else if (1 == rank)
+        CHECK_EQUAL(1005, edges_num); // Not owned edges included
     }
-    else if (1 == rank) {
-      CHECK_EQUAL(321, my_cells_num); // Not owned cells included
-      CHECK_EQUAL((size_t)1, cells.psize()); // Not owned cells included
+    else {
+      if (0 == rank)
+        CHECK_EQUAL(1438, edges_num);
+      else if (1 == rank)
+        CHECK_EQUAL(1444, edges_num); // Not owned edges included
     }
   }
 
-   rval = pcomm->filter_pstatus(cells, PSTATUS_NOT_OWNED, PSTATUS_NOT);
-   CHECK_ERR(rval);
-
-   my_cells_num = cells.size();
-   if (test_nb_cells && 2 == procs) {
-     if (0 == rank) {
-       CHECK_EQUAL(963, my_cells_num); // Gather set cells included
-       if (mixed_elements)
-         CHECK_EQUAL((size_t)4, cells.psize()); // Gather set cells included
-       else
-         CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells included
-     }
-     else if (1 == rank) {
-       CHECK_EQUAL(321, my_cells_num); // Not owned cells excluded
-       CHECK_EQUAL((size_t)1, cells.psize()); // Not owned cells excluded
-     }
-   }
-
-  if (0 == rank) {
-    // Get gather set
-    EntityHandle gather_set;
-    ReadUtilIface* readUtilIface;
-    rval = mb.query_interface(readUtilIface);
-    CHECK_ERR(rval);
-    rval = readUtilIface->get_gather_set(gather_set);
-    CHECK_ERR(rval);
+  rval = pcomm->filter_pstatus(local_edges, PSTATUS_NOT_OWNED, PSTATUS_NOT);
+  CHECK_ERR(rval);
 
-    // Get gather set entities
-    Range gather_ents;
-    rval = mb.get_entities_by_handle(gather_set, gather_ents);
-    CHECK_ERR(rval);
+  edges_num = local_edges.size();
+  if (2 == procs) {
+    if (rcbzoltan) {
+      if (0 == rank)
+        CHECK_EQUAL(1005, edges_num);
+      else if (1 == rank)
+        CHECK_EQUAL(915, edges_num); // Not owned edges excluded
+    }
+    else {
+      if (0 == rank)
+        CHECK_EQUAL(1438, edges_num);
+      else if (1 == rank)
+        CHECK_EQUAL(482, edges_num); // Not owned edges excluded
+    }
+  }
 
-    // Remove gather set vertices in processor 0
-    verts = subtract(verts, gather_ents);
+  // Get local cells
+  Range local_cells;
+  rval = mb.get_entities_by_type(0, MBPOLYGON, local_cells);
+  CHECK_ERR(rval);
 
-    // Remove gather set edges in processor 0
-    edges = subtract(edges, gather_ents);
+  int cells_num = local_cells.size();
+  if (2 == procs) {
+    CHECK_EQUAL(321, cells_num);
 
-    // Remove gather set cells in processor 0
-    cells = subtract(cells, gather_ents);
+    if (rcbzoltan) {
+      if (no_mixed_elements)
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+      else
+        CHECK_EQUAL((size_t)2, local_cells.psize());
+     }
+    else {
+      if (0 == rank) {
+        if (no_mixed_elements)
+          CHECK_EQUAL((size_t)1, local_cells.psize());
+        else
+          CHECK_EQUAL((size_t)2, local_cells.psize());
+      }
+      else if (1 == rank)
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+    }
   }
 
-  my_verts_num = verts.size();
-  if (test_nb_nodes && 2 == procs) {
-    if (0 == rank)
-      CHECK_EQUAL(1120, my_verts_num); // Gather set vertices excluded
-    else if (1 == rank)
-      CHECK_EQUAL(160, my_verts_num); // Not owned vertices excluded
-  }
+  rval = pcomm->filter_pstatus(local_cells, PSTATUS_NOT_OWNED, PSTATUS_NOT);
+  CHECK_ERR(rval);
 
-  std::cout << "proc: " << rank << " verts:" << my_verts_num << "\n";
+  cells_num = local_cells.size();
+  if (2 == procs) {
+    CHECK_EQUAL(321, cells_num);
 
-  int total_verts;
-  MPI_Reduce(&my_verts_num, &total_verts, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
-  if (0 == rank) {
-    std::cout << "total vertices: " << total_verts << "\n";
-    if (test_nb_nodes)
-      CHECK_EQUAL(total_verts, num_verts);
+    if (rcbzoltan) {
+      if (no_mixed_elements)
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+      else
+        CHECK_EQUAL((size_t)2, local_cells.psize());
+    }
+    else {
+      if (0 == rank) {
+        if (no_mixed_elements)
+          CHECK_EQUAL((size_t)1, local_cells.psize());
+        else
+          CHECK_EQUAL((size_t)2, local_cells.psize());
+      }
+      else if (1 == rank)
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+    }
   }
 
-  my_edges_num = edges.size();
-  if (test_nb_edges && 2 == procs) {
-    if (0 == rank)
-      CHECK_EQUAL(1438, my_edges_num); // Gather set edges excluded
-    else if (1 == rank)
-      CHECK_EQUAL(482, my_edges_num); // Not owned edges excluded
+  std::cout << "proc: " << rank << " verts:" << verts_num << "\n";
+
+  int total_verts_num;
+  MPI_Reduce(&verts_num, &total_verts_num, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
+  if (0 == rank) {
+    std::cout << "total vertices: " << total_verts_num << "\n";
+    CHECK_EQUAL(1280, total_verts_num);
   }
 
-  std::cout << "proc: " << rank << " edges:" << my_edges_num << "\n";
+  std::cout << "proc: " << rank << " edges:" << edges_num << "\n";
 
-  int total_edges;
-  MPI_Reduce(&my_edges_num, &total_edges, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
+  int total_edges_num;
+  MPI_Reduce(&edges_num, &total_edges_num, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
   if (0 == rank) {
-    std::cout << "total edges: " << total_edges << "\n";
-    if (test_nb_edges)
-      CHECK_EQUAL(total_edges, num_edges);
+    std::cout << "total edges: " << total_edges_num << "\n";
+    CHECK_EQUAL(1920, total_edges_num);
   }
 
-  my_cells_num = cells.size();
-  if (test_nb_cells && 2 == procs) {
-    if (0 == rank) {
-      CHECK_EQUAL(321, my_cells_num); // Gather set cells excluded
-      if (mixed_elements)
-        CHECK_EQUAL((size_t)2, cells.psize()); // Gather set cells excluded
-      else
-        CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells excluded
-    }
-    else if (1 == rank) {
-      CHECK_EQUAL(321, my_cells_num); // Not owned cells excluded
-      CHECK_EQUAL((size_t)1, cells.psize()); // Not owned cells excluded
-    }
+  std::cout << "proc: " << rank << " cells:" << cells_num << "\n";
+
+  int total_cells_num;
+  MPI_Reduce(&cells_num, &total_cells_num, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
+  if (0 == rank) {
+    std::cout << "total cells: " << total_cells_num << "\n";
+    CHECK_EQUAL(642, total_cells_num);
   }
 
-   std::cout << "proc: " << rank << " cells:" << my_cells_num << "\n";
+#ifdef HDF5_PARALLEL
+  std::string write_options("PARALLEL=WRITE_PART;");
 
-   int total_cells;
-   MPI_Reduce(&my_cells_num, &total_cells, 1, MPI_INTEGER, MPI_SUM, 0, pcomm->proc_config().proc_comm());
-   if (0 == rank) {
-     std::cout << "total cells: " << total_cells << "\n";
-     if (test_nb_cells)
-       CHECK_EQUAL(total_cells, num_cells);
-   }
+  std::string output_file = "test_mpas";
+  if (rcbzoltan)
+    output_file += "_rcbzoltan";
+  if (no_mixed_elements)
+    output_file += "_no_mixed_elements";
+  output_file += ".h5m";
 
-  std::string write_options("PARALLEL=WRITE_PART;");
-  mb.write_file("test_mpas.h5m", NULL, write_options.c_str());
+  mb.write_file(output_file.c_str(), NULL, write_options.c_str());
+#endif
 }
 
-void test_multiple_loads_of_same_file()
+void gather_one_cell_var(int gather_set_rank)
 {
   Core moab;
   Interface& mb = moab;
+
   EntityHandle file_set;
-  ErrorCode rval;
-  rval = mb.create_meshset(MESHSET_SET, file_set);
+  ErrorCode rval = mb.create_meshset(MESHSET_SET, file_set);
   CHECK_ERR(rval);
 
-  // Read first only header information, no mesh, no variable
-  std::string opts("PARALLEL=READ_PART;PARTITION;NOMESH;VARIABLE=;PARTITION_METHOD=TRIVIAL");
-  rval = mb.load_file(example, &file_set, opts.c_str());
-  CHECK_ERR(rval);
+  read_options = "PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL;PARALLEL_RESOLVE_SHARED_ENTS";
+  std::ostringstream gather_set_option;
+  gather_set_option << ";GATHER_SET=" << gather_set_rank;
+  read_options += gather_set_option.str();
 
-  // Create mesh, no variable
-  opts="PARALLEL=READ_PART;PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;PARTITION_METHOD=TRIVIAL;VARIABLE=";
-  // Create gather set in processor 1
-  opts += std::string(";GATHER_SET=1");
-  rval = mb.load_file(example, &file_set, opts.c_str());
-  CHECK_ERR(rval);
-
-  // Read variable ke at timestep 0, no mesh
-  opts = "PARALLEL=READ_PART;PARTITION;PARTITION_METHOD=TRIVIAL;NOMESH;VARIABLE=ke;TIMESTEP=0";
-  rval = mb.load_file(example, &file_set, opts.c_str());
+  rval = mb.load_file(example, &file_set, read_options.c_str());
   CHECK_ERR(rval);
 
   ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
   int procs = pcomm->proc_config().proc_size();
   int rank = pcomm->proc_config().proc_rank();
 
-  // Make check runs this test in two processors
-  if (2 == procs) {
-    Range verts;
-    rval = mb.get_entities_by_type(0, MBVERTEX, verts);
-    CHECK_ERR(rval);
+  // Make sure gather_set_rank is valid
+  if (gather_set_rank < 0 || gather_set_rank >= procs)
+    return;
 
-    Range edges;
-    rval = mb.get_entities_by_type(0, MBEDGE, edges);
-    CHECK_ERR(rval);
+  Range cells, cells_owned;
+  rval = mb.get_entities_by_type(file_set, MBPOLYGON, cells);
+  CHECK_ERR(rval);
 
-    Range cells;
-    rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
+  // Get local owned cells
+  rval = pcomm->filter_pstatus(cells, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &cells_owned);
+  CHECK_ERR(rval);
+
+  EntityHandle gather_set = 0;
+  if (gather_set_rank == rank) {
+    // Get gather set
+    ReadUtilIface* readUtilIface;
+    mb.query_interface(readUtilIface);
+    rval = readUtilIface->get_gather_set(gather_set);
     CHECK_ERR(rval);
+    assert(gather_set != 0);
+  }
 
-    int my_verts_num = verts.size();
-    int my_edges_num = edges.size();
-    int my_cells_num = cells.size();
+  Tag ke_tag0, gid_tag;
+  rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0, MB_TAG_DENSE);
+  CHECK_ERR(rval);
 
-    if (0 == rank) {
-      CHECK_EQUAL(1120, my_verts_num);
-      CHECK_EQUAL(1438, my_edges_num);
-      CHECK_EQUAL(321, my_cells_num);
-      CHECK_EQUAL((size_t)2, cells.psize());
-
-      const double eps = 1e-20;
-      double val[2];
-
-      // Check tag for cell variable ke at timestep 0
-      Tag ke_tag0;
-      rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
-      CHECK_ERR(rval);
-
-      // Check ke0 tag values on first pentagon and first hexagon
-      EntityHandle cell_ents[] = {cells[0], cells[12]};
-      rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
-      CHECK_REAL_EQUAL(15.001, val[0], eps);
-      CHECK_REAL_EQUAL(16.013, val[1], eps);
-    }
-    else if (1 == rank) {
-      CHECK_EQUAL(2402, my_verts_num); // Gather set vertices included; Not owned vertices included
-      CHECK_EQUAL(3364, my_edges_num); // Gather set edges included; Not owned edges included
-      CHECK_EQUAL(963, my_cells_num); // Gather set cells included; Not owned cells included
-      CHECK_EQUAL((size_t)3, cells.psize()); // Gather set cells included; Not owned cells included
-
-      // Get gather set
-      EntityHandle gather_set;
-      ReadUtilIface* readUtilIface;
-      rval = mb.query_interface(readUtilIface);
-      CHECK_ERR(rval);
-      rval = readUtilIface->get_gather_set(gather_set);
-      CHECK_ERR(rval);
-
-      // Get gather set entities
-      Range gather_ents;
-      rval = mb.get_entities_by_handle(gather_set, gather_ents);
-      CHECK_ERR(rval);
-
-      // Remove gather set vertices in processor 1
-      verts = subtract(verts, gather_ents);
-      my_verts_num = verts.size();
-      CHECK_EQUAL(1122, my_verts_num); // Gather set vertices excluded; Not owned vertices included
-
-      // Remove gather set edges in processor 1
-      edges = subtract(edges, gather_ents);
-      my_edges_num = edges.size();
-      CHECK_EQUAL(1444, my_edges_num); // Gather set edges excluded; Not owned edges included
-
-      // Remove gather set cells in processor 1
-      cells = subtract(cells, gather_ents);
-      my_cells_num = cells.size();
-      CHECK_EQUAL(321, my_cells_num); // Gather set cells excluded; Not owned cells included
-      CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells excluded; Not owned cells included
-    }
+  rval = mb.tag_get_handle(GLOBAL_ID_TAG_NAME, 1, MB_TYPE_INTEGER, gid_tag, MB_TAG_DENSE);
+  CHECK_ERR(rval);
+
+  pcomm->gather_data(cells_owned, ke_tag0, gid_tag, gather_set, gather_set_rank);
+
+  if (gather_set_rank == rank) {
+    // Get gather set cells
+    Range gather_set_cells;
+    rval = mb.get_entities_by_type(gather_set, MBPOLYGON, gather_set_cells);
+    CHECK_EQUAL((size_t)642, gather_set_cells.size());
+    CHECK_EQUAL((size_t)2, gather_set_cells.psize());
+
+    // Check ke0 tag values on 4 gather set cells: first pentagon, last pentagon,
+    // first hexagon and last hexagon
+    EntityHandle cell_ents[] = {gather_set_cells[0], gather_set_cells[11],
+                                gather_set_cells[12], gather_set_cells[641]};
+    double ke0_val[4];
+    rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 4, ke0_val);
+
+    CHECK_REAL_EQUAL(15.001, ke0_val[0], eps);
+    CHECK_REAL_EQUAL(15.012, ke0_val[1], eps);
+    CHECK_REAL_EQUAL(16.013, ke0_val[2], eps);
+    CHECK_REAL_EQUAL(16.642, ke0_val[3], eps);
   }
 }
 
-void test_multiple_loads_of_same_file_no_mixed_elements()
+void multiple_loads_of_same_file(bool no_mixed_elements)
 {
   Core moab;
   Interface& mb = moab;
+
+  // Need a file set for nomesh to work right
   EntityHandle file_set;
   ErrorCode rval;
   rval = mb.create_meshset(MESHSET_SET, file_set);
   CHECK_ERR(rval);
 
   // Read first only header information, no mesh, no variable
-  std::string opts("PARALLEL=READ_PART;PARTITION;NOMESH;VARIABLE=;PARTITION_METHOD=TRIVIAL;NO_MIXED_ELEMENTS");
-  rval = mb.load_file(example, &file_set, opts.c_str());
+  read_options = "PARALLEL=READ_PART;PARTITION;NOMESH;VARIABLE=;PARTITION_METHOD=TRIVIAL";
+  if (no_mixed_elements)
+    read_options += ";NO_MIXED_ELEMENTS";
+
+  rval = mb.load_file(example, &file_set, read_options.c_str());
   CHECK_ERR(rval);
 
   // Create mesh, no variable
-  opts="PARALLEL=READ_PART;PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;PARTITION_METHOD=TRIVIAL;NO_MIXED_ELEMENTS;VARIABLE=";
-  // Create gather set in processor 1
-  opts += std::string(";GATHER_SET=1");
-  rval = mb.load_file(example, &file_set, opts.c_str());
+  read_options = "PARALLEL=READ_PART;PARTITION;PARALLEL_RESOLVE_SHARED_ENTS;PARTITION_METHOD=TRIVIAL;VARIABLE=";
+  if (no_mixed_elements)
+    read_options += ";NO_MIXED_ELEMENTS";
+
+  rval = mb.load_file(example, &file_set, read_options.c_str());
   CHECK_ERR(rval);
 
   // Read variable ke at timestep 0, no mesh
-  opts = "PARALLEL=READ_PART;PARTITION;PARTITION_METHOD=TRIVIAL;NO_MIXED_ELEMENTS;NOMESH;VARIABLE=ke;TIMESTEP=0";
-  rval = mb.load_file(example, &file_set, opts.c_str());
+  read_options = "PARALLEL=READ_PART;PARTITION;PARTITION_METHOD=TRIVIAL;NOMESH;VARIABLE=ke;TIMESTEP=0";
+  if (no_mixed_elements)
+    read_options += ";NO_MIXED_ELEMENTS";
+
+  rval = mb.load_file(example, &file_set, read_options.c_str());
+  CHECK_ERR(rval);
+
+  Range local_verts;
+  rval = mb.get_entities_by_type(file_set, MBVERTEX, local_verts);
+  CHECK_ERR(rval);
+
+  Range local_edges;
+  rval = mb.get_entities_by_type(file_set, MBEDGE, local_edges);
+  CHECK_ERR(rval);
+
+  Range local_cells;
+  rval = mb.get_entities_by_type(file_set, MBPOLYGON, local_cells);
   CHECK_ERR(rval);
 
   ParallelComm* pcomm = ParallelComm::get_pcomm(&mb, 0);
   int procs = pcomm->proc_config().proc_size();
   int rank = pcomm->proc_config().proc_rank();
 
-  // Make check runs this test in two processors
+  // Make check runs this test on two processors
   if (2 == procs) {
-    Range verts;
-    rval = mb.get_entities_by_type(0, MBVERTEX, verts);
-    CHECK_ERR(rval);
+    CHECK_EQUAL((size_t)321, local_cells.size());
 
-    Range edges;
-    rval = mb.get_entities_by_type(0, MBEDGE, edges);
+    // Check tag for cell variable ke at timestep 0
+    Tag ke_tag0;
+    rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
     CHECK_ERR(rval);
 
-    Range cells;
-    rval = mb.get_entities_by_type(0, MBPOLYGON, cells);
+    // Get ke0 tag values on 3 local cells
+    EntityHandle cell_ents[] = {local_cells[0], local_cells[160], local_cells[320]};
+    double ke0_val[3];
+    rval = mb.tag_get_data(ke_tag0, cell_ents, 3, ke0_val);
     CHECK_ERR(rval);
 
-    int my_verts_num = verts.size();
-    int my_edges_num = edges.size();
-    int my_cells_num = cells.size();
-
     if (0 == rank) {
-      CHECK_EQUAL(1120, my_verts_num);
-      CHECK_EQUAL(1438, my_edges_num);
-      CHECK_EQUAL(321, my_cells_num);
-      CHECK_EQUAL((size_t)1, cells.psize());
-
-      const double eps = 1e-20;
-      double val[2];
-
-      // Check tag for cell variable ke at timestep 0
-      Tag ke_tag0;
-      rval = mb.tag_get_handle("ke0", 1, MB_TYPE_DOUBLE, ke_tag0);
-      CHECK_ERR(rval);
-
-      // Check ke0 tag values on first pentagon and first hexagon
-      EntityHandle cell_ents[] = {cells[0], cells[12]};
-      rval = mb.tag_get_data(ke_tag0, &cell_ents[0], 2, val);
-      CHECK_REAL_EQUAL(15.001, val[0], eps);
-      CHECK_REAL_EQUAL(16.013, val[1], eps);
+      CHECK_EQUAL((size_t)1120, local_verts.size());
+      CHECK_EQUAL((size_t)1438, local_edges.size());
+      if (no_mixed_elements)
+        CHECK_EQUAL((size_t)1, local_cells.psize());
+      else
+        CHECK_EQUAL((size_t)2, local_cells.psize());
+
+      CHECK_REAL_EQUAL(15.001, ke0_val[0], eps);
+      CHECK_REAL_EQUAL(16.161, ke0_val[1], eps);
+      CHECK_REAL_EQUAL(16.321, ke0_val[2], eps);
     }
     else if (1 == rank) {
-      CHECK_EQUAL(2402, my_verts_num); // Gather set vertices included; Not owned vertices included
-      CHECK_EQUAL(3364, my_edges_num); // Gather set edges included; Not owned edges included
-      CHECK_EQUAL(963, my_cells_num); // Gather set cells included; Not owned cells included
-      CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells included; Not owned cells included
-
-      // Get gather set
-      EntityHandle gather_set;
-      ReadUtilIface* readUtilIface;
-      rval = mb.query_interface(readUtilIface);
-      CHECK_ERR(rval);
-      rval = readUtilIface->get_gather_set(gather_set);
-      CHECK_ERR(rval);
-
-      // Get gather set entities
-      Range gather_ents;
-      rval = mb.get_entities_by_handle(gather_set, gather_ents);
-      CHECK_ERR(rval);
-
-      // Remove gather set vertices in processor 1
-      verts = subtract(verts, gather_ents);
-      my_verts_num = verts.size();
-      CHECK_EQUAL(1122, my_verts_num); // Gather set vertices excluded; Not owned vertices included
-
-      // Remove gather set edges in processor 1
-      edges = subtract(edges, gather_ents);
-      my_edges_num = edges.size();
-      CHECK_EQUAL(1444, my_edges_num); // Gather set edges excluded; Not owned edges included
-
-      // Remove gather set cells in processor 1
-      cells = subtract(cells, gather_ents);
-      my_cells_num = cells.size();
-      CHECK_EQUAL(321, my_cells_num); // Gather set cells excluded; Not owned cells included
-      CHECK_EQUAL((size_t)1, cells.psize()); // Gather set cells excluded; Not owned cells included
+      CHECK_EQUAL((size_t)1122, local_verts.size());
+      CHECK_EQUAL((size_t)1444, local_edges.size());
+      CHECK_EQUAL((size_t)1, local_cells.psize());
+
+      CHECK_REAL_EQUAL(16.322, ke0_val[0], eps);
+      CHECK_REAL_EQUAL(16.482, ke0_val[1], eps);
+      CHECK_REAL_EQUAL(16.642, ke0_val[2], eps);
     }
   }
 }

Repository URL: https://bitbucket.org/fathomteam/moab/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the moab-dev mailing list