Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
72e472d
Add Eric's nompi stub
bobpaw Apr 26, 2024
0ac4fcd
Add MPI stubs and refactor typedefs
bobpaw Apr 30, 2024
1924c52
Add extern C and fix MPI_Init and MPI_Finalize return type
bobpaw Apr 30, 2024
ec115cd
Replace MPI_Comm_Split with PCU_Comm_Split
bobpaw Apr 30, 2024
235c4b4
Remove direct MPI calls from tests
bobpaw Apr 30, 2024
fd4ae56
Do not use mpirun for tests with SCOREC_NO_MPI
bobpaw Apr 30, 2024
df6efc1
Replace stub MPI_Init/Finalize with empty #define
bobpaw Apr 30, 2024
79556cc
Fixed stub unused parameter warnings
bobpaw May 2, 2024
a29f81f
Fix g++ warnings
bobpaw May 3, 2024
1f16b30
Remove spurious pnompi error message
bobpaw May 5, 2024
5dda7d0
Only run 1-proc tests with SCOREC_NO_MPI
bobpaw Sep 11, 2024
43d90f9
Set msg peer in pcu_pnompi receive2
bobpaw May 6, 2024
98f0659
feat: Implement PCU_Time without MPI_WTime
bobpaw Jun 14, 2024
07727ed
fix: Add pcu_pnompi_types.h to install headers
bobpaw Jun 14, 2024
7db4547
Fix set_test_properties on multiproc tests
bobpaw Sep 11, 2024
4c5db4c
Merge branch 'develop' into apw/nompi
bobpaw Oct 25, 2024
12fc04f
Merge branch 'develop' into apw/nompi
bobpaw Feb 4, 2025
b76d8f1
Fix compilation errors and update pcu_pnompi.c
bobpaw Feb 5, 2025
86e7a8d
cleanup pcu::Order
bobpaw Feb 5, 2025
4083386
remove obsolete pmpi functions
bobpaw Feb 6, 2025
ca2165d
readd C function arguments in definition
bobpaw Feb 6, 2025
0541cff
indent CMake testing file
bobpaw Feb 6, 2025
e1d38cb
Update CMakeLists.txt
bobpaw Feb 6, 2025
74c2617
add example mpi-nompi project
bobpaw Feb 9, 2025
53d2adb
Merge branch 'develop' into apw/nompi
bobpaw Feb 10, 2025
c9682f3
fix GitHub actions file
bobpaw Feb 10, 2025
11d50df
ci: run tests for mpi-nompi example
bobpaw Feb 10, 2025
73707dc
ci: add allreduce to mpi-nompi example
bobpaw Feb 10, 2025
36b09bd
remove PCU_Comm_Allreduce
bobpaw Feb 10, 2025
d150eb6
remove MPI_Init replacement macro from PCU.h
bobpaw Feb 12, 2025
da81781
remove MPI_SUM from pcu_pnompi_types.h
bobpaw Feb 12, 2025
ce7c4e8
replace PCU_Comm_Allgather with PCU::Allgather
bobpaw Feb 13, 2025
f88e21e
Replace MPI_Comm with PCU_Comm and add PCU::PCU()
bobpaw Feb 19, 2025
d4ee513
use default PCU constructor in example project
bobpaw Feb 19, 2025
5cda076
add SCOREC_NO_MPI guards to example doc/myprogramm
bobpaw Feb 19, 2025
3189c08
expand pcu_merge arguments and remove pcu_merge2
bobpaw Feb 19, 2025
28eaa3a
ci: add ctest output on failure
bobpaw Feb 19, 2025
54dc9ce
update example/mpi-nompi print order
bobpaw Feb 19, 2025
bac66ad
replace PCU_Comm_Split with PCU::Split
bobpaw Feb 19, 2025
46be470
replace PCU_Comm_Split with PCU::Split in tests
bobpaw Feb 19, 2025
0a65fea
use default PCU constructor in capstone tests
bobpaw Feb 19, 2025
615663d
rename and deprecate GetMPIComm and SwitchMPIComm
bobpaw Feb 19, 2025
153f19b
Revert "update example/mpi-nompi print order"
bobpaw Feb 19, 2025
2100560
add example test file for CTest
bobpaw Feb 20, 2025
e4baca1
install headers to GNUInstallDirs variable
bobpaw Feb 20, 2025
b0f5bf1
use std::vector in example
bobpaw Feb 20, 2025
437da68
add nodiscard to PCU::SwitchMPIComm and PCU::SwitchComm
bobpaw Feb 20, 2025
d6576a9
Revert "remove MPI_Init replacement macro from PCU.h"
bobpaw Feb 24, 2025
953f86f
add pcu::PCU_Init and pcu::PCU_Finalize
bobpaw Feb 24, 2025
6f7ec1a
use static pcu object in capstone tests
bobpaw Feb 24, 2025
9ac70dd
fix bug in example project
bobpaw Feb 24, 2025
cdf7e3f
change PCU::Split to return std::unique_ptr
bobpaw Feb 24, 2025
95110eb
add PCU::DupComm
bobpaw Feb 24, 2025
0ce7897
remove PCU original comm and ownership and use Dup
bobpaw Feb 25, 2025
7d6dbd7
add errors when using nompi with Zoltan/CGNS
bobpaw Feb 25, 2025
f192d2d
use DupComm in apfZoltan
bobpaw Feb 25, 2025
0069474
fix pumi_mesh switchPCU
bobpaw Feb 25, 2025
07232e8
fix pumi_mesh.cc errors introduced by 36b09bd7c
bobpaw Feb 27, 2025
262a5c9
remove undefined PCU_GetGlobal
bobpaw Feb 28, 2025
f11237b
change PCU_Init to avoid re-initializing MPI
bobpaw Mar 3, 2025
fa2e70b
change pcu::PCU_Init to pcu::Init
bobpaw Mar 4, 2025
981b20a
bump PUMI to 4.0.0
bobpaw Mar 4, 2025
9aa2271
revert to MPI_Init in sim_countBL
bobpaw Mar 4, 2025
f4f79c1
bump SCOREC major version in examples
bobpaw Mar 4, 2025
4895e2d
add const to PCU::Allgather send data
bobpaw Mar 7, 2025
974b2ef
remove direct MPI calls from CGNS code
bobpaw Mar 7, 2025
aec006e
quote CMake variable in example/mpi-nompi
bobpaw Mar 11, 2025
75fe494
fix include in sim_countBL test
bobpaw Mar 11, 2025
42c4d6a
fix buffer overflow
bobpaw Mar 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- { name: GNU, CC: gcc-10, CXX: g++-10 }
- { name: LLVM, CC: clang, CXX: clang++ }
build_type: [Debug, Release]
no_mpi: [OFF, ON]

steps:
- uses: actions/checkout@v4
Expand All @@ -30,7 +31,7 @@ jobs:
env:
MPICH_CXX: ${{matrix.compiler.CXX}}
MPICH_CC: ${{matrix.compiler.CC}}
run: cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DCMAKE_CXX_COMPILER=mpicxx -DCMAKE_C_COMPILER=mpicc -DCMAKE_VERBOSE_MAKEFILE=ON -DMESHES=${{github.workspace}}/pumi-meshes -DIS_TESTING=ON -DSCOREC_CXX_WARNINGS=ON -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/install
run: cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DCMAKE_CXX_COMPILER=mpicxx -DCMAKE_C_COMPILER=mpicc -DCMAKE_VERBOSE_MAKEFILE=ON -DMESHES=${{github.workspace}}/pumi-meshes -DIS_TESTING=ON -DSCOREC_CXX_WARNINGS=ON -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/build/install -DSCOREC_NO_MPI=${{matrix.no_mpi}}

- name: Build
env:
Expand All @@ -54,3 +55,20 @@ jobs:
run: |
cmake -S ${{github.workspace}}/doc -B ${{github.workspace}}/buildExample -DCMAKE_CXX_COMPILER=mpicxx -DSCOREC_PREFIX=${{github.workspace}}/build/install
cmake --build ${{github.workspace}}/buildExample

- name: Build MPI-NoMPI Example
# Test if a SCOREC_NO_MPI build works with MPI applications.
if: >-
matrix.compiler.name == 'GNU' && matrix.build_type == 'Release' &&
matrix.no_mpi == 'ON'
env:
MPICH_CXX: ${{matrix.compiler.CXX}}
MPICH_CC: ${{matrix.compiler.CC}}
run: >
cmake -S ${{github.workspace}}/example/mpi-nompi
-B ${{github.workspace}}/example/mpi-nompi/build
-DCMAKE_CXX_COMPILER=mpicxx
-DSCOREC_PREFIX=${{github.workspace}}/build/install ;
cmake --build ${{github.workspace}}/example/mpi-nompi/build ;
ctest --test-dir ${{github.workspace}}/example/mpi-nompi/build
--output-on-failure
20 changes: 18 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ endif()
# This is the top level CMake file for the SCOREC build
cmake_minimum_required(VERSION 3.8)

project(SCOREC VERSION 3.0.3 LANGUAGES CXX C)
project(SCOREC VERSION 4.0.0 LANGUAGES CXX C)

include(cmake/bob.cmake)
include(cmake/xsdk.cmake)
Expand All @@ -29,6 +29,15 @@ else()
bob_set_cxx_standard(14)
endif()

#
# option related to MPI
#
option(SCOREC_NO_MPI "Disable MPI support. When enabled only serial execution is supported." OFF)
message(STATUS "SCOREC_NO_MPI: ${SCOREC_NO_MPI}")
if(SCOREC_NO_MPI AND ENABLE_CGNS)
message(FATAL_ERROR "SCOREC_NO_MPI is incompatible with CGNS.")
endif()

# Set some default compiler flags that should always be used
if(NOT USE_XSDK_DEFAULTS)
bob_set_shared_libs()
Expand Down Expand Up @@ -133,7 +142,10 @@ endif()

macro(scorec_export_library target)
bob_export_target(${target})
install(FILES ${HEADERS} DESTINATION include)
install(FILES ${HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
target_include_directories(${target} INTERFACE
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
endmacro(scorec_export_library)

if(ENABLE_SIMMETRIX)
Expand Down Expand Up @@ -162,6 +174,10 @@ if(ENABLE_CGNS)
add_definitions(-DHAVE_CGNS)
endif()

configure_file(SCOREC_config.h.in SCOREC_config.h)
install(FILES "${CMAKE_BINARY_DIR}/SCOREC_config.h" DESTINATION include)
include_directories(PUBLIC "$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>")

# Include the SCOREC project packages
add_subdirectory(lion)
add_subdirectory(pcu)
Expand Down
7 changes: 7 additions & 0 deletions SCOREC_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef SCOREC_CONFIG_H
#define SCOREC_CONFIG_H

#cmakedefine SCOREC_NO_MPI

#endif // SCOREC_CONFIG_H

1 change: 0 additions & 1 deletion apf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ add_library(apf ${SOURCES})
# Include directories
target_include_directories(apf PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)

# Link this library to these others
Expand Down
33 changes: 20 additions & 13 deletions apf/apfCGNS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,9 @@ CellElementReturn WriteElements(const CGNS &cgns, apf::Mesh *m, apf::GlobalNumbe
cgp_error_exit();

std::vector<int> allNumbersForThisType(m->getPCU()->Peers(), 0);
MPI_Allgather(&numbersByElementType[o], 1, MPI_INT, allNumbersForThisType.data(), 1,
MPI_INT, m->getPCU()->GetMPIComm());
m->getPCU()->Allgather(
&numbersByElementType[o], allNumbersForThisType.data(), 1
);

cgsize_t num = 0;
for (int i = 0; i < m->getPCU()->Self(); i++)
Expand Down Expand Up @@ -656,8 +657,7 @@ void AddBocosToMainBase(const CGNS &cgns, const CellElementReturn &cellResults,
}

std::vector<int> allNumbersForThisType(m->getPCU()->Peers(), 0);
MPI_Allgather(&number, 1, MPI_INT, allNumbersForThisType.data(), 1,
MPI_INT, m->getPCU()->GetMPIComm());
m->getPCU()->Allgather(&number, allNumbersForThisType.data(), 1);

cgsize_t num = 0;
for (int i = 0; i < m->getPCU()->Self(); i++)
Expand All @@ -684,19 +684,16 @@ void AddBocosToMainBase(const CGNS &cgns, const CellElementReturn &cellResults,
}
}
std::vector<int> cacheStarts(m->getPCU()->Peers(), 0);
MPI_Allgather(&cacheStart, 1, MPI_INT, cacheStarts.data(), 1,
MPI_INT, m->getPCU()->GetMPIComm());
m->getPCU()->Allgather(&cacheStart, cacheStarts.data(), 1);
std::vector<int> cacheEnds(m->getPCU()->Peers(), 0);
MPI_Allgather(&cacheEnd, 1, MPI_INT, cacheEnds.data(), 1,
MPI_INT, m->getPCU()->GetMPIComm());
m->getPCU()->Allgather(&cacheEnd, cacheEnds.data(), 1);
return std::make_pair(cacheStarts, cacheEnds);
};

const auto globalElementList = [&m](const std::vector<cgsize_t> &bcList, std::vector<cgsize_t> &allElements) {
std::vector<int> sizes(m->getPCU()->Peers(), 0); // important initialiser
const int l = bcList.size();
MPI_Allgather(&l, 1, MPI_INT, sizes.data(), 1,
MPI_INT, m->getPCU()->GetMPIComm());
m->getPCU()->Allgather(&l, sizes.data(), 1);

int totalLength = 0;
for (const auto &i : sizes)
Expand All @@ -708,9 +705,15 @@ void AddBocosToMainBase(const CGNS &cgns, const CellElementReturn &cellResults,
displacement[i] = displacement[i - 1] + sizes[i - 1];

allElements.resize(totalLength);
#ifndef SCOREC_NO_MPI
PCU_Comm comm;
m->getPCU()->DupComm(&comm);
MPI_Allgatherv(bcList.data(), bcList.size(), MPI_INT, allElements.data(),
sizes.data(), displacement.data(), MPI_INT,
m->getPCU()->GetMPIComm());
sizes.data(), displacement.data(), MPI_INT, comm);
MPI_Comm_free(&comm);
#else
std::copy(bcList.begin(), bcList.end(), allElements.begin());
#endif
};

const auto doVertexBC = [&](const auto &iter) {
Expand Down Expand Up @@ -1046,7 +1049,8 @@ void WriteCGNS(const char *prefix, apf::Mesh *m, const apf::CGNSBCMap &cgnsBCMap
sizes[2] = 0; // nodes are unsorted, as defined by api

// Copy communicator
auto communicator = m->getPCU()->GetMPIComm();
PCU_Comm communicator;
m->getPCU()->DupComm(&communicator);
cgp_mpi_comm(communicator);
//
cgp_pio_mode(CGP_INDEPENDENT);
Expand Down Expand Up @@ -1134,6 +1138,9 @@ void WriteCGNS(const char *prefix, apf::Mesh *m, const apf::CGNSBCMap &cgnsBCMap
destroyGlobalNumbering(gcn);
//
cgp_close(cgns.index);
#ifndef SCOREC_NO_MPI
MPI_Comm_free(&communicator);
#endif
}
} // namespace

Expand Down
1 change: 0 additions & 1 deletion apf_cap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ include(GNUInstallDirs)

target_include_directories(apf_cap PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

scorec_export_library(apf_cap)
Expand Down
1 change: 0 additions & 1 deletion apf_sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ target_link_libraries(apf_sim PUBLIC ${SIMMODSUITE_LIBS})
target_include_directories(gmi_sim PUBLIC ${SIMMODSUITE_INCLUDE_DIR})
target_include_directories(apf_sim PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)

option(ENABLE_FIELDSIM "Enable use of FieldSim from Simmetrix SimModSuite" FALSE)
Expand Down
1 change: 0 additions & 1 deletion can/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ add_library(can INTERFACE)
# Include directories
target_include_directories(can INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)

scorec_export_library(can)
Expand Down
1 change: 0 additions & 1 deletion crv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ add_library(crv ${SOURCES})
# Include directories
target_include_directories(crv INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)

# Link this package to these libraries
Expand Down
4 changes: 2 additions & 2 deletions doc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ set(SCOREC_PREFIX "" CACHE STRING "Directory where SCOREC is installed")
# If SCOREC_PREFIX was specified, only link to that directory,
# i.e. don't link to another installation in /usr/lib by mistake
if (SCOREC_PREFIX)
find_package(SCOREC 3.0.0 REQUIRED CONFIG PATHS ${SCOREC_PREFIX} NO_DEFAULT_PATH)
find_package(SCOREC 4 REQUIRED CONFIG PATHS ${SCOREC_PREFIX} NO_DEFAULT_PATH)
else()
# IF SCOREC_PREFIX was not specified, look in typical system directories,
# and also in CMAKE_PREFIX_PATH (environment variable)
find_package(
SCOREC #package name, has to be SCOREC
3.0.0 #version. can be omitted, and will match any installed version
4 #version. can be omitted, and will match any installed version
#greater than or equal to this one, as long as the major number
#is the same
REQUIRED #indicate that SCOREC is really needed to compile
Expand Down
6 changes: 5 additions & 1 deletion doc/myprogram.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include <PCU.h>
#include "mylibrary.h"
int main(int argc, char** argv) {
#ifndef SCOREC_NO_MPI
MPI_Init(&argc,&argv);
pcu::PCU PCUObj = pcu::PCU(MPI_COMM_WORLD);
#endif
pcu::PCU PCUObj;
makeMesh(&PCUObj);
#ifndef SCOREC_NO_MPI
MPI_Finalize();
#endif
return 0;
}
1 change: 0 additions & 1 deletion dsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ add_library(dsp ${SOURCES})
# Include directories
target_include_directories(apf INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)

# Link this package to these libraries
Expand Down
24 changes: 24 additions & 0 deletions example/mpi-nompi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.8)
project(mpi-nompi VERSION 1.0.0 LANGUAGES CXX)

# Allow the user to indicate where they installed SCOREC
# via "-DSCOREC_PREFIX=/home/somewhere" when calling `cmake`
set(SCOREC_PREFIX "" CACHE STRING "Directory where SCOREC is installed")

# If SCOREC_PREFIX was specified then use only that directory.
if (SCOREC_PREFIX)
find_package(SCOREC 4 REQUIRED CONFIG PATHS "${SCOREC_PREFIX}" NO_DEFAULT_PATH)
else()
find_package(SCOREC 4 REQUIRED CONFIG)
endif()

add_executable(hello hello.cc)
target_link_libraries(hello PRIVATE SCOREC::core)
add_executable(test_coll test_coll.cc)
target_link_libraries(test_coll PRIVATE SCOREC::core)

enable_testing()
add_test(NAME coll1 COMMAND mpirun -np 1 $<TARGET_FILE:test_coll>)
add_test(NAME coll2 COMMAND mpirun -np 2 $<TARGET_FILE:test_coll>)
add_test(NAME coll4 COMMAND mpirun -np 4 $<TARGET_FILE:test_coll>)

6 changes: 6 additions & 0 deletions example/mpi-nompi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Example: Using SCOREC_NO_MPI in an MPI application

This example demonstrates how to combine a SCOREC_NO_MPI build of core with an
application that is using MPI. This is the prime use case for the SCOREC_NO_MPI
option.

89 changes: 89 additions & 0 deletions example/mpi-nompi/hello.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include <iostream>
#include <vector>

#include <mpi.h>
#include <PCU.h>
#include <gmi_mesh.h>
#include <apf.h>
#include <apfBox.h>
#include <apfMesh2.h>

template <typename T>
void print_vector(const std::vector<T> &v);

int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
{ // pcu object scope
pcu::PCU PCUObj;
// Print rank info.
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (rank == 0)
std::cout << "MPI size: " << size << "; PCU size: " <<
PCUObj.Peers() << std::endl;
for (int i = 0; i < size; ++i) {
if (rank == i)
std::cout << "Hello from MPI rank: " << rank << "; PCU rank: " <<
PCUObj.Self() << std::endl;
MPI_Barrier(MPI_COMM_WORLD);
}
// Test SCOREC functions.
gmi_register_mesh();
apf::Mesh2* m = apf::makeMdsBox(1, 1, 1, 1, 1, 1, 0, &PCUObj);
apf::destroyMesh(m);
// MPI Allreduce
int val = rank + 1, sum;
MPI_Allreduce(&val, &sum, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
int pval = rank + 1, psum;
psum = PCUObj.Add(pval);
for (int i = 0; i < size; ++i) {
if (rank == i)
std::cout << "MPI(" << rank << ") sum: " << sum <<
"; PCU sum: " << psum << std::endl;
MPI_Barrier(MPI_COMM_WORLD);
}
// Test Allgather
std::vector<int> vals1(size);
MPI_Allgather(&val, 1, MPI_INT, vals1.data(), 1, MPI_INT, MPI_COMM_WORLD);
std::vector<int> pvals1(PCUObj.Peers());
PCUObj.Allgather(&val, pvals1.data(), 1);
for (int i = 0; i < size; ++i) {
if (rank == i) {
std::cout << "MPI(" << rank << ") gather: ";
print_vector(vals1);
std::cout << "; PCU gather: ";
print_vector(pvals1);
std::cout << std::endl;
}
MPI_Barrier(MPI_COMM_WORLD);
}
int val2[2] = {val, -val};
std::vector<int> vals2(2 * size);
MPI_Allgather(val2, 2, MPI_INT, vals2.data(), 2, MPI_INT, MPI_COMM_WORLD);
std::vector<int> pvals2(2 * PCUObj.Peers());
PCUObj.Allgather(val2, pvals2.data(), 2);
for (int i = 0; i < size; ++i) {
if (rank == i) {
std::cout << "MPI(" << rank << ") gather2: ";
print_vector(vals2);
std::cout << "; PCU gather2: ";
print_vector(pvals2);
std::cout << std::endl;
}
MPI_Barrier(MPI_COMM_WORLD);
}
} // pcu object scope
MPI_Finalize();
return 0;
}

template <typename T>
void print_vector(const std::vector<T>& v) {
std::cout << "[";
for (int i = 0; i < v.size(); ++i) {
if (i != 0) std::cout << ", ";
std::cout << v[i];
}
std::cout << "]";
}
Loading