Skip to content

Commit bd3721b

Browse files
authored
Merge pull request #433 from jacobmerson/pcu-object-breaking
Breaking changes with PCU. - Ported PCU interface to not use global state - i.e., mesh creation requires passing in a PCU instance - The new interface uses C++ - A C interface for PCU still exists in pcu_c.cc - Create an instance of the C handle struct "PCU_t" - The original pcu.c functions can be used by passing this struct - Renamed source and headers files: - PCU.h became PCU_C.h: PCU.h was repurposed as the C++ header - pcu.c became pcu_c.cc: pcu.c was deleted and pcu_c.cc created without history - more details on the history is here: #433 (comment) - Build documentation (`make doc`) to generate doxygen based docs or see https://www.scorec.rpi.edu/pumi/doxygen/pcu.html for basic PCU.cc usage
2 parents 0191626 + 7e54d7f commit bd3721b

File tree

348 files changed

+5076
-4895
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

348 files changed

+5076
-4895
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ endif()
66
# This is the top level CMake file for the SCOREC build
77
cmake_minimum_required(VERSION 3.8)
88

9-
project(SCOREC VERSION 2.2.10 LANGUAGES CXX C)
9+
project(SCOREC VERSION 2.3.0 LANGUAGES CXX C)
1010

1111
include(cmake/bob.cmake)
1212
include(cmake/xsdk.cmake)

Doxyfile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ INPUT = \
793793
@CMAKE_CURRENT_SOURCE_DIR@/gmi/gmi_mesh.h \
794794
@CMAKE_CURRENT_SOURCE_DIR@/gmi/gmi_analytic.h \
795795
@CMAKE_CURRENT_SOURCE_DIR@/gmi/gmi_null.h \
796-
@CMAKE_CURRENT_SOURCE_DIR@/pcu/pcu.c \
796+
@CMAKE_CURRENT_SOURCE_DIR@/pcu/PCU.cc \
797797
@CMAKE_CURRENT_SOURCE_DIR@/mth/mth.dox \
798798
@CMAKE_CURRENT_SOURCE_DIR@/mth/mth.h \
799799
@CMAKE_CURRENT_SOURCE_DIR@/mth/mthVector.h \

Doxyfile_internal.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ INPUT = \
826826
@CMAKE_CURRENT_SOURCE_DIR@/gmi/gmi_mesh.h \
827827
@CMAKE_CURRENT_SOURCE_DIR@/gmi/gmi_analytic.h \
828828
@CMAKE_CURRENT_SOURCE_DIR@/gmi/gmi_null.h \
829-
@CMAKE_CURRENT_SOURCE_DIR@/pcu/pcu.c \
829+
@CMAKE_CURRENT_SOURCE_DIR@/pcu/PCU.cc \
830830
@CMAKE_CURRENT_SOURCE_DIR@/mth/mth.dox \
831831
@CMAKE_CURRENT_SOURCE_DIR@/mth/mth.h \
832832
@CMAKE_CURRENT_SOURCE_DIR@/mth/mthVector.h \

apf/apf.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include "apfNew.h"
1313
#include "apfDynamicArray.h"
1414

15+
namespace pcu{
16+
class PCU;
17+
}
18+
1519
#include <vector>
1620
#include <map>
1721
#include <limits>
@@ -460,7 +464,7 @@ class Integrator
460464
* process-local integrations into a global mesh integration,
461465
* if that is the user's goal.
462466
*/
463-
virtual void parallelReduce();
467+
virtual void parallelReduce(pcu::PCU*);
464468
protected:
465469
int order;
466470
int ipnode;

apf/apfCGNS.cc

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
* BSD license as described in the LICENSE file in the top-level directory.
66
*/
77

8-
#include <PCU.h>
98
#include "apfMesh.h"
109
#include "apfNumbering.h"
1110
#include "apfNumberingClass.h"
1211
#include "apfShape.h"
1312
#include "apfFieldData.h"
1413
#include <pcu_util.h>
1514
#include <lionPrint.h>
16-
//
1715
#include <sstream>
1816
#include <fstream>
1917
#include <iostream>
@@ -47,7 +45,7 @@ static Count count(apf::Mesh *m, int dim)
4745
{
4846
const int local = apf::countOwned(m, dim);
4947
int total = local;
50-
PCU_Add_Ints(&total, 1); // size of total array
48+
m->getPCU()->Add<int>(&total, 1); // size of total array
5149
return std::make_pair(total, local);
5250
}
5351

@@ -290,7 +288,7 @@ void WriteFields(const CGNS &cgns, const std::vector<std::vector<apf::MeshEntity
290288
}
291289

292290
int size = data.size();
293-
PCU_Add_Ints(&size, 1); // size of total array
291+
m->getPCU()->Add<int>(&size, 1); // size of total array
294292

295293
// oddness of the api
296294
rmin[1] = rmin[0];
@@ -505,7 +503,7 @@ CellElementReturn WriteElements(const CGNS &cgns, apf::Mesh *m, apf::GlobalNumbe
505503
m->end(cellIter);
506504
numbersByElementType[o] = counter;
507505
int total = counter;
508-
PCU_Add_Ints(&total, 1); // size of total array
506+
m->getPCU()->Add<int>(&total, 1); // size of total array
509507
globalNumbersByElementType[o] = total;
510508
}
511509
cgsize_t allTotal = std::accumulate(globalNumbersByElementType.begin(), globalNumbersByElementType.end(), 0);
@@ -546,12 +544,12 @@ CellElementReturn WriteElements(const CGNS &cgns, apf::Mesh *m, apf::GlobalNumbe
546544
if (cgp_section_write(cgns.index, cgns.base, cgns.zone, name.c_str(), cgnsElementOrder[o], globalStart, globalEnd, 0, &sectionNumber)) // global start, end within the file for that element type
547545
cgp_error_exit();
548546

549-
std::vector<int> allNumbersForThisType(PCU_Comm_Peers(), 0);
547+
std::vector<int> allNumbersForThisType(m->getPCU()->Peers(), 0);
550548
MPI_Allgather(&numbersByElementType[o], 1, MPI_INT, allNumbersForThisType.data(), 1,
551-
MPI_INT, PCU_Get_Comm());
549+
MPI_INT, m->getPCU()->GetMPIComm());
552550

553551
cgsize_t num = 0;
554-
for (int i = 0; i < PCU_Comm_Self(); i++)
552+
for (int i = 0; i < m->getPCU()->Self(); i++)
555553
num += allNumbersForThisType[i];
556554

557555
cgsize_t elStart = globalStart + num;
@@ -635,7 +633,7 @@ void AddBocosToMainBase(const CGNS &cgns, const CellElementReturn &cellResults,
635633
int startOfBCBlock = startingLocation + 1;
636634
const int number = bc.second.size();
637635
int total = number;
638-
PCU_Add_Ints(&total, 1); // size of total array
636+
m->getPCU()->Add<int>(&total, 1); // size of total array
639637
if (total > 0)
640638
{
641639
const auto allEnd = startOfBCBlock + total - 1; //one-based
@@ -657,12 +655,12 @@ void AddBocosToMainBase(const CGNS &cgns, const CellElementReturn &cellResults,
657655
}
658656
}
659657

660-
std::vector<int> allNumbersForThisType(PCU_Comm_Peers(), 0);
658+
std::vector<int> allNumbersForThisType(m->getPCU()->Peers(), 0);
661659
MPI_Allgather(&number, 1, MPI_INT, allNumbersForThisType.data(), 1,
662-
MPI_INT, PCU_Get_Comm());
660+
MPI_INT, m->getPCU()->GetMPIComm());
663661

664662
cgsize_t num = 0;
665-
for (int i = 0; i < PCU_Comm_Self(); i++)
663+
for (int i = 0; i < m->getPCU()->Self(); i++)
666664
num += allNumbersForThisType[i];
667665

668666
cgsize_t elStart = startOfBCBlock + num;
@@ -685,34 +683,34 @@ void AddBocosToMainBase(const CGNS &cgns, const CellElementReturn &cellResults,
685683
cacheEnd = allEnd;
686684
}
687685
}
688-
std::vector<int> cacheStarts(PCU_Comm_Peers(), 0);
686+
std::vector<int> cacheStarts(m->getPCU()->Peers(), 0);
689687
MPI_Allgather(&cacheStart, 1, MPI_INT, cacheStarts.data(), 1,
690-
MPI_INT, PCU_Get_Comm());
691-
std::vector<int> cacheEnds(PCU_Comm_Peers(), 0);
688+
MPI_INT, m->getPCU()->GetMPIComm());
689+
std::vector<int> cacheEnds(m->getPCU()->Peers(), 0);
692690
MPI_Allgather(&cacheEnd, 1, MPI_INT, cacheEnds.data(), 1,
693-
MPI_INT, PCU_Get_Comm());
691+
MPI_INT, m->getPCU()->GetMPIComm());
694692
return std::make_pair(cacheStarts, cacheEnds);
695693
};
696694

697-
const auto globalElementList = [](const std::vector<cgsize_t> &bcList, std::vector<cgsize_t> &allElements) {
698-
std::vector<int> sizes(PCU_Comm_Peers(), 0); // important initialiser
695+
const auto globalElementList = [&m](const std::vector<cgsize_t> &bcList, std::vector<cgsize_t> &allElements) {
696+
std::vector<int> sizes(m->getPCU()->Peers(), 0); // important initialiser
699697
const int l = bcList.size();
700698
MPI_Allgather(&l, 1, MPI_INT, sizes.data(), 1,
701-
MPI_INT, PCU_Get_Comm());
699+
MPI_INT, m->getPCU()->GetMPIComm());
702700

703701
int totalLength = 0;
704702
for (const auto &i : sizes)
705703
totalLength += i;
706704

707-
std::vector<int> displacement(PCU_Comm_Peers(), -1);
705+
std::vector<int> displacement(m->getPCU()->Peers(), -1);
708706
displacement[0] = 0;
709707
for (std::size_t i = 1; i < displacement.size(); i++)
710708
displacement[i] = displacement[i - 1] + sizes[i - 1];
711709

712710
allElements.resize(totalLength);
713711
MPI_Allgatherv(bcList.data(), bcList.size(), MPI_INT, allElements.data(),
714712
sizes.data(), displacement.data(), MPI_INT,
715-
PCU_Get_Comm());
713+
m->getPCU()->GetMPIComm());
716714
};
717715

718716
const auto doVertexBC = [&](const auto &iter) {
@@ -755,7 +753,7 @@ void AddBocosToMainBase(const CGNS &cgns, const CellElementReturn &cellResults,
755753
for (const auto &p : iter->second)
756754
{
757755
const auto se = BCEntityAdder(EdgeLoop, p, startingLocation);
758-
for (int i = 0; i < PCU_Comm_Peers(); i++)
756+
for (int i = 0; i < m->getPCU()->Peers(); i++)
759757
{
760758
PCU_ALWAYS_ASSERT_VERBOSE(se.first[i] == se.first[0], "Must all be the same ");
761759
PCU_ALWAYS_ASSERT_VERBOSE(se.second[i] == se.second[0], "Must all be the same ");
@@ -779,7 +777,7 @@ void AddBocosToMainBase(const CGNS &cgns, const CellElementReturn &cellResults,
779777
{
780778
const auto se = BCEntityAdder(FaceLoop, p, startingLocation);
781779

782-
for (int i = 0; i < PCU_Comm_Peers(); i++)
780+
for (int i = 0; i < m->getPCU()->Peers(); i++)
783781
{
784782
PCU_ALWAYS_ASSERT_VERBOSE(se.first[i] == se.first[0], "Must all be the same ");
785783
PCU_ALWAYS_ASSERT_VERBOSE(se.second[i] == se.second[0], "Must all be the same ");
@@ -1011,7 +1009,7 @@ void WriteCGNS(const char *prefix, apf::Mesh *m, const apf::CGNSBCMap &cgnsBCMap
10111009
{
10121010
static_assert(std::is_same<cgsize_t, int>::value, "cgsize_t not compiled as int");
10131011

1014-
const auto myRank = PCU_Comm_Self();
1012+
const auto myRank = m->getPCU()->Self();
10151013
const Count vertexCount = count(m, 0);
10161014
const Count edgeCount = count(m, 1);
10171015
const Count faceCount = count(m, 2);
@@ -1031,7 +1029,7 @@ void WriteCGNS(const char *prefix, apf::Mesh *m, const apf::CGNSBCMap &cgnsBCMap
10311029
// PCU_Barrier();
10321030
// }
10331031

1034-
PCU_Barrier();
1032+
m->getPCU()->Barrier();
10351033
if (myRank == 0)
10361034
{
10371035
std::cout << "*******Global Mesh Stats*****************\n";
@@ -1048,7 +1046,7 @@ void WriteCGNS(const char *prefix, apf::Mesh *m, const apf::CGNSBCMap &cgnsBCMap
10481046
sizes[2] = 0; // nodes are unsorted, as defined by api
10491047

10501048
// Copy communicator
1051-
auto communicator = PCU_Get_Comm();
1049+
auto communicator = m->getPCU()->GetMPIComm();
10521050
cgp_mpi_comm(communicator);
10531051
//
10541052
cgp_pio_mode(CGP_INDEPENDENT);

apf/apfCavityOp.cc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* BSD license as described in the LICENSE file in the top-level directory.
66
*/
77

8-
#include <PCU.h>
98
#include "apfCavityOp.h"
109
#include "apf.h"
1110
#include "apfMesh2.h"
@@ -134,10 +133,10 @@ bool CavityOp::requestLocality(MeshEntity** entities, int count)
134133

135134
bool CavityOp::sendPullRequests(std::vector<PullRequest>& received)
136135
{
137-
int done = PCU_Min_Int(requests.empty());
136+
int done = mesh->getPCU()->Min<int>(requests.empty());
138137
if (done) return false;
139138
/* throw in the local pull requests */
140-
int self = PCU_Comm_Self();
139+
int self = mesh->getPCU()->Self();
141140
received.reserve(requests.size());
142141
APF_ITERATE(Requests,requests,it)
143142
{
@@ -147,7 +146,7 @@ bool CavityOp::sendPullRequests(std::vector<PullRequest>& received)
147146
received.push_back(request);
148147
}
149148
/* now communicate the rest */
150-
PCU_Comm_Begin();
149+
mesh->getPCU()->Begin();
151150
APF_ITERATE(Requests,requests,it)
152151
{
153152
CopyArray remotes;
@@ -156,18 +155,17 @@ bool CavityOp::sendPullRequests(std::vector<PullRequest>& received)
156155
{
157156
int remotePart = rit->peer;
158157
MeshEntity* remoteEntity = rit->entity;
159-
PCU_COMM_PACK(remotePart,remoteEntity);
160-
}
158+
mesh->getPCU()->Pack(remotePart,remoteEntity); }
161159
}
162160
requests.clear();
163-
PCU_Comm_Send();
164-
while (PCU_Comm_Listen())
161+
mesh->getPCU()->Send();
162+
while (mesh->getPCU()->Listen())
165163
{
166164
PullRequest request;
167-
request.to = PCU_Comm_Sender();
168-
while ( ! PCU_Comm_Unpacked())
165+
request.to = mesh->getPCU()->Sender();
166+
while ( ! mesh->getPCU()->Unpacked())
169167
{
170-
PCU_COMM_UNPACK(request.e);
168+
mesh->getPCU()->Unpack(request.e);
171169
received.push_back(request);
172170
}
173171
}

0 commit comments

Comments
 (0)