Skip to content

Commit

Permalink
Fix bug when RAPIDJSON_DONT_IMPORT_NUMPY set, but Python not fully di…
Browse files Browse the repository at this point in the history
…sabled

Store MPIComm addresses as instances rather than pointers
  • Loading branch information
langmm committed Sep 22, 2023
1 parent d20688c commit d7b8219
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
14 changes: 3 additions & 11 deletions communication/communicators/MPIComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,11 @@ void MPIComm::init() {
handle->procs.clear();
handle->tag = 0;
std::vector<std::string> adrs = communication::utils::split(this->address.address(), ",");
addresses.push_back(&this->address);
addresses.emplace_back(this->address.address());
if (adrs.size() > 1) {
addresses[0]->address(adrs[0]);
addresses[0].address(adrs[0]);
for (size_t i = 1; i < adrs.size(); i++) {
Address tempadr(adrs[i]);
addresses.push_back(&tempadr);
addresses.emplace_back(adrs[i]);
}
}

Expand All @@ -109,13 +108,6 @@ void MPIComm::init() {
}
}

void MPIComm::close() {
for (size_t i = 1; i < addresses.size(); i++)
delete addresses[i];
addresses.clear();
CommBase::close();
}

int MPIComm::mpi_comm_source_id() const {
#if defined(MPIINSTALLED) && defined(MPI_COMM_WORLD)
if (direction == SEND)
Expand Down
6 changes: 2 additions & 4 deletions communication/communicators/MPIComm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ class MPIComm : public CommBase<mpi_registry_t> {
ADD_CONSTRUCTORS(MPI)

#if defined(MPIINSTALLED) && defined(MPI_COMM_WORLD)
/*! \copydoc Comm_t::close */
void close() override;
/*! \copydoc Comm_t::comm_nmsg */
int comm_nmsg(DIRECTION dir=NONE) const override;

Expand All @@ -91,11 +89,11 @@ class MPIComm : public CommBase<mpi_registry_t> {

#ifdef YGG_TEST
public:
std::vector<utils::Address *>& getAddresses() { return addresses; }
std::vector<utils::Address>& getAddresses() { return addresses; }
#endif

private:
std::vector<utils::Address *> addresses;
std::vector<utils::Address> addresses;
};

}
Expand Down
6 changes: 3 additions & 3 deletions test/unittest/tests/communicators/mpicommtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ TEST(MPIComm, constructor) {
EXPECT_NE(mpic2.getName().find("tempinitMPI"), std::string::npos);
utils::Address adr3("[50000], 51000");
MPIComm_tester mpic3(name, adr3, RECV);
std::vector<utils::Address*> adrlist = mpic3.getAddresses();
std::vector<utils::Address> adrlist = mpic3.getAddresses();
EXPECT_EQ(adrlist.size(), 2);
EXPECT_EQ(adrlist[0]->address(), "[50000]");
EXPECT_EQ(adrlist[1]->address(), "51000");
EXPECT_EQ(adrlist[0].address(), "[50000]");
EXPECT_EQ(adrlist[1].address(), "51000");
}

TEST(MPIComm, sourceID) {
Expand Down
7 changes: 6 additions & 1 deletion test/unittest/tests/datatypes/dtypetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,14 @@ TEST(dtype, PythonInit) {
}

#ifndef YGGDRASIL_DISABLE_PYTHON_C_API
#ifdef RAPIDJSON_DONT_IMPORT_NUMPY
#define CHECK_ARRAY_API EXPECT_FALSE(rapidjson_ARRAY_API)
#else // RAPIDJSON_DONT_IMPORT_NUMPY
#define CHECK_ARRAY_API EXPECT_TRUE(rapidjson_ARRAY_API)
#endif // RAPIDJSON_DONT_IMPORT_NUMPY
#define DO_PYTHON(name) \
TEST(generic_t, name) { \
EXPECT_TRUE(rapidjson_ARRAY_API); \
CHECK_ARRAY_API; \
generic_t v = init_generic_generate("{\"type\": \"" #name "\"}"); \
generic_t x = init_generic_null(); \
python_t data; \
Expand Down

0 comments on commit d7b8219

Please sign in to comment.