[MOAB-dev] commit/MOAB: danwu: Delete MOAB instance if return early in main() for some examples.
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Tue Sep 24 10:45:34 CDT 2013
1 new commit in MOAB:
https://bitbucket.org/fathomteam/moab/commits/c5ea1479e283/
Changeset: c5ea1479e283
Branch: master
User: danwu
Date: 2013-09-24 17:45:22
Summary: Delete MOAB instance if return early in main() for some examples.
Affected #: 4 files
diff --git a/examples/GetEntities.cpp b/examples/GetEntities.cpp
index d9dc34e..5124529 100644
--- a/examples/GetEntities.cpp
+++ b/examples/GetEntities.cpp
@@ -29,19 +29,28 @@ int main(int argc, char **argv) {
// instantiate & load a mesh from a file
Core *mb = new Core();
ErrorCode rval = mb->load_mesh(test_file_name.c_str());
- if (MB_SUCCESS != rval) return 1;
+ if (MB_SUCCESS != rval) {
+ delete mb;
+ return 1;
+ }
Range ents;
// get all entities in the database
rval = mb->get_entities_by_handle(0, ents);
- if (MB_SUCCESS != rval) return 1;
+ if (MB_SUCCESS != rval) {
+ delete mb;
+ return 1;
+ }
for (Range::iterator it = ents.begin(); it != ents.end(); it++) {
if (MBVERTEX == mb->type_from_handle(*it)) {
Range adjs;
rval = mb->get_adjacencies(&(*it), 1, 3, false, adjs);
- if (MB_SUCCESS != rval) return 1;
+ if (MB_SUCCESS != rval) {
+ delete mb;
+ return 1;
+ }
cout << "Vertex " << mb->id_from_handle(*it) << " adjacencies:" << endl;
adjs.print();
}
@@ -49,9 +58,13 @@ int main(int argc, char **argv) {
const EntityHandle *connect;
int num_connect;
rval = mb->get_connectivity(*it, connect, num_connect);
- if (MB_SUCCESS != rval) return 1;
+ if (MB_SUCCESS != rval) {
+ delete mb;
+ return 1;
+ }
cout << CN::EntityTypeName(mb->type_from_handle(*it)) << " " << mb->id_from_handle(*it) << " vertex connectivity is: ";
- for (int i = 0; i < num_connect; i++) cout << mb->id_from_handle(connect[i]) << " ";
+ for (int i = 0; i < num_connect; i++)
+ cout << mb->id_from_handle(connect[i]) << " ";
cout << endl;
}
}
diff --git a/examples/HelloParMOAB.cpp b/examples/HelloParMOAB.cpp
index 03366f9..5bcc4ab 100644
--- a/examples/HelloParMOAB.cpp
+++ b/examples/HelloParMOAB.cpp
@@ -20,20 +20,23 @@ int main(int argc, char **argv)
string options;
- // need option handling here for input filename
+ // Need option handling here for input filename
if (argc > 1){
- //user has input a mesh file
+ // user has input a mesh file
test_file_name = argv[1];
}
options = "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS";
- // get MOAB instance and read the file with the specified options
- Interface *mb = new Core;
- if (NULL == mb) return 1;
- // get the ParallelComm instance
+ // Get MOAB instance and read the file with the specified options
+ Interface* mb = new Core;
+ if (NULL == mb)
+ return 1;
+
+ // Get the ParallelComm instance
ParallelComm* pcomm = new ParallelComm(mb, MPI_COMM_WORLD);
- int nprocs = pcomm->proc_config().proc_size(), rank = pcomm->proc_config().proc_rank();
+ 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)
@@ -41,59 +44,76 @@ int main(int argc, char **argv)
<< " on " << nprocs << " processors\n";
ErrorCode rval = mb->load_file(test_file_name.c_str(), 0, options.c_str());
- if (rval != MB_SUCCESS) return 1;
+ if (rval != MB_SUCCESS) {
+ delete mb;
+ return 1;
+ }
Range shared_ents;
- // get entities shared with all other processors
+ // Get entities shared with all other processors
rval = pcomm->get_shared_entities(-1, shared_ents);
- if (rval != MB_SUCCESS) return 1;
+ if (rval != MB_SUCCESS) {
+ delete mb;
+ return 1;
+ }
- // filter shared entities with not not_owned, which means owned
+ // Filter shared entities with not not_owned, which means owned
Range owned_entities;
rval = pcomm->filter_pstatus(shared_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &owned_entities);
- if (rval != MB_SUCCESS) return 1;
+ if (rval != MB_SUCCESS) {
+ delete mb;
+ return 1;
+ }
- unsigned int nums[4]={0}; // to store the owned entities per dimension
- for (int i=0; i<4; i++) nums[i]=(int)owned_entities.num_of_dimension(i);
+ unsigned int nums[4] = {0}; // to store the owned entities per dimension
+ for (int i = 0; i < 4; i++)
+ nums[i] = (int)owned_entities.num_of_dimension(i);
vector<int> rbuf(nprocs*4, 0);
- MPI_Gather( nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, MPI_COMM_WORLD);
- // print the stats gathered:
+ MPI_Gather(nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, MPI_COMM_WORLD);
+ // Print the stats gathered:
if (rank == 0) {
- for (int i=0; i<nprocs; i++)
+ for (int i = 0; i < nprocs; i++)
cout << " Shared, owned entities on proc " << i << ": " << rbuf[4*i] << " verts, " <<
- rbuf[4*i+1] << " edges, " << rbuf[4*i+2] << " faces, " << rbuf[4*i+3] << " elements" << endl;
+ rbuf[4*i + 1] << " edges, " << rbuf[4*i + 2] << " faces, " << rbuf[4*i + 3] << " elements" << endl;
}
- // Now exchange 1 layer of ghost elements, using vertices as bridge
- // (we could have done this as part of reading process, using the PARALLEL_GHOSTS read option)
+ // Now exchange 1 layer of ghost elements, using vertices as bridge
+ // (we could have done this as part of reading process, using the PARALLEL_GHOSTS read option)
rval = pcomm->exchange_ghost_cells(3, // int ghost_dim,
0, // int bridge_dim,
1, //int num_layers,
0, //int addl_ents,
true); // bool store_remote_handles);
- if (rval != MB_SUCCESS) return 1;
+ if (rval != MB_SUCCESS) {
+ delete mb;
+ return 1;
+ }
- // repeat the reports, after ghost exchange
+ // Repeat the reports, after ghost exchange
shared_ents.clear();
owned_entities.clear();
rval = pcomm->get_shared_entities(-1, shared_ents);
- if (rval != MB_SUCCESS) return 1;
+ if (rval != MB_SUCCESS) {
+ delete mb;
+ return 1;
+ }
rval = pcomm->filter_pstatus(shared_ents, PSTATUS_NOT_OWNED, PSTATUS_NOT, -1, &owned_entities);
- if (rval != MB_SUCCESS) return 1;
+ if (rval != MB_SUCCESS) {
+ delete mb;
+ return 1;
+ }
// find out how many shared entities of each dimension are owned on this processor
- for (int i=0; i<4; i++)
- nums[i]=(int)owned_entities.num_of_dimension(i);
+ for (int i = 0; i < 4; i++)
+ nums[i] = (int)owned_entities.num_of_dimension(i);
// gather the statistics on processor 0
- MPI_Gather( nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, comm);
- if (rank == 0)
- {
+ MPI_Gather(nums, 4, MPI_INT, &rbuf[0], 4, MPI_INT, 0, comm);
+ if (rank == 0) {
cout << " \n\n After exchanging one ghost layer: \n";
- for (int i=0; i<nprocs; i++)
- {
+ for (int i = 0; i < nprocs; i++) {
cout << " Shared, owned entities on proc " << i << ": " << rbuf[4*i] << " verts, " <<
- rbuf[4*i+1] << " edges, " << rbuf[4*i+2] << " faces, " << rbuf[4*i+3] << " elements" << endl;
+ rbuf[4*i + 1] << " edges, " << rbuf[4*i + 2] << " faces, " << rbuf[4*i + 3] << " elements" << endl;
}
}
diff --git a/examples/old/ObbTree.cpp b/examples/old/ObbTree.cpp
index f83b440..ff4aadf 100644
--- a/examples/old/ObbTree.cpp
+++ b/examples/old/ObbTree.cpp
@@ -22,9 +22,10 @@ int main(int argc, char **argv) {
moab::Range tris;
//moab::OrientedBoxTreeTool::Settings settings;
- rval = mb->get_entities_by_type( 0, moab::MBTRI, tris );
+ rval = mb->get_entities_by_type(0, moab::MBTRI, tris);
if (rval != moab::MB_SUCCESS) {
std::cerr << "Couldn't get triangles." << std::endl;
+ delete mb;
return 1;
}
@@ -33,7 +34,8 @@ int main(int argc, char **argv) {
//rval = tool.build(tris, tree_root, &settings);
rval = tool.build(tris, tree_root);
if (rval != moab::MB_SUCCESS) {
- std::cerr << "Could'nt build tree." << std::endl;
+ std::cerr << "Could'nt build tree." << std::endl;
+ delete mb;
return 1;
}
@@ -42,6 +44,7 @@ int main(int argc, char **argv) {
rval = tool.box(tree_root, box_center, box_axis1, box_axis2, box_axis3);
if (rval != moab::MB_SUCCESS) {
std::cerr << "Couldn't get box for tree root set.";
+ delete mb;
return 1;
}
@@ -52,17 +55,19 @@ int main(int argc, char **argv) {
std::vector<double> intersections;
std::vector<moab::EntityHandle> intersection_facets;
- for (int i=0; i<3; i++)
- pnt_start[i] = box_center[i]-box_axis1[i];
+ for (int i = 0; i < 3; i++)
+ pnt_start[i] = box_center[i] - box_axis1[i];
- if (ray_length>0) // normalize ray direction
- for (int j=0; j<3; j++)
- box_axis1[j]=2*box_axis1[j]/ray_length;
+ if (ray_length > 0) { // normalize ray direction
+ for (int j = 0; j < 3; j++)
+ box_axis1[j] = 2 * box_axis1[j] / ray_length;
+ }
rval = tool.ray_intersect_triangles(intersections, intersection_facets,
tree_root, 10e-12, pnt_start, box_axis1,
&ray_length);
if (rval != moab::MB_SUCCESS) {
std::cerr << "Couldn't ray tracing.";
+ delete mb;
return 1;
}
@@ -71,9 +76,8 @@ int main(int argc, char **argv) {
std::cout << " ray direction: " << box_axis1[0] << " " << box_axis1[1] << " " << box_axis1[2] << "\n";
std::cout << "# of intersections : " << intersections.size() << std::endl;
std::cout << "intersection distances are on";
- for (unsigned int i = 0; i < intersections.size(); i++) {
+ for (unsigned int i = 0; i < intersections.size(); i++)
std::cout << " " << intersections[i];
- }
std::cout << " of ray length " << ray_length << std::endl;
delete mb;
diff --git a/examples/old/simple/GetEntities.cpp b/examples/old/simple/GetEntities.cpp
index 8d235fd..8368d9f 100644
--- a/examples/old/simple/GetEntities.cpp
+++ b/examples/old/simple/GetEntities.cpp
@@ -8,18 +8,20 @@ int main(int argc, char **argv) {
return 0;
}
- // instantiate & load a mesh from a file
+ // Instantiate & load a mesh from a file
moab::Core *mb = new moab::Core();
moab::ErrorCode rval = mb->load_mesh(argv[1]);
- if (moab::MB_SUCCESS != rval) return 1;
+ if (moab::MB_SUCCESS != rval)
+ return 1;
moab::Range ents;
- // iterate over dimensions
+ // Iterate over dimensions
for (int d = 0; d <= 3; d++) {
ents.clear();
rval = mb->get_entities_by_dimension(0, d, ents);
- if (moab::MB_SUCCESS != rval) return 1;
+ if (moab::MB_SUCCESS != rval)
+ return 1;
std::cout << "Found " << ents.size() << " " << d << "-dimensional entities:" << std::endl;
for (moab::Range::iterator it = ents.begin(); it != ents.end(); it++) {
moab::EntityHandle ent = *it;
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