Skip to content

Commit

Permalink
Remove Winsocks functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Oct 17, 2023
1 parent fde69cb commit ff8c373
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 75 deletions.
9 changes: 0 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,6 @@ target_include_directories(openPMD PUBLIC
$<INSTALL_INTERFACE:include>
)

# Winsock library for gethostname() function on Windows
if(WIN32)
# need to link this publically as WSAStartup() and WSACleanup() need to be
# called surrounding the gethostname() function on Windows
# and it needs to be done at client site since the winsocks API is
# initialized statically per process....
target_link_libraries(openPMD PUBLIC ws2_32)
endif()

# Catch2 for unit tests
if(openPMD_BUILD_TESTING)
add_library(openPMD::thirdparty::Catch2 INTERFACE IMPORTED)
Expand Down
25 changes: 13 additions & 12 deletions include/openPMD/ChunkInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ namespace host_info
enum class Method
{
POSIX_HOSTNAME,
WINSOCKS_HOSTNAME,
MPI_PROCESSOR_NAME
};

Expand All @@ -108,7 +107,6 @@ namespace host_info
* Currently recognized are:
*
* * posix_hostname
* * winsocks_hostname
* * mpi_processor_name
*
* For backwards compatibility reasons, "hostname" is also recognized as a
Expand Down Expand Up @@ -152,24 +150,27 @@ namespace host_info
chunk_assignment::RankMeta byMethodCollective(MPI_Comm, Method);
#endif

/*
* The following block contains one wrapper for each native hostname retrieval
* method. The purpose is to have the same function pointer type for all
* of them.
*/
/*
* The following block contains one wrapper for each native hostname
* retrieval method. The purpose is to have the same function pointer type
* for all of them.
*/

/*
* @todo Replace _WIN32 with proper Winsocks macro,
* add POSIX availability macro.
*/
#ifdef _WIN32
std::string winsocks_hostname();
#define openPMD_POSIX_AVAILABLE false
#else
#define openPMD_POSIX_AVAILABLE true
#endif

#if openPMD_POSIX_AVAILABLE
std::string posix_hostname();
#endif

#if openPMD_HAVE_MPI
std::string mpi_processor_name();
#endif

} // namespace host_info
} // namespace openPMD

#undef openPMD_POSIX_AVAILABLE
48 changes: 13 additions & 35 deletions src/ChunkInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@

#include <utility>

/*
* @todo Replace _WIN32 with proper Winsocks macro,
* add POSIX availability macro.
*/

#ifdef _WIN32
#include <windows.h>
#define openPMD_POSIX_AVAILABLE false
#else
#define openPMD_POSIX_AVAILABLE true
#endif

#if openPMD_POSIX_AVAILABLE
#include <unistd.h>
#endif

Expand Down Expand Up @@ -71,7 +70,6 @@ namespace host_info
static std::map<std::string, Method> const map{
{"posix_hostname", Method::POSIX_HOSTNAME},
{"hostname", Method::POSIX_HOSTNAME},
{"winsocks_hostname", Method::WINSOCKS_HOSTNAME},
{"mpi_processor_name", Method::MPI_PROCESSOR_NAME}};
if (descr == "hostname")
{
Expand All @@ -84,21 +82,13 @@ namespace host_info
return map.at(descr);
}

// @todo do this properly
#ifdef _WIN32
#define openPMD_POSIX_AVAILABLE false
#else
#define openPMD_POSIX_AVAILABLE true
#endif
bool methodAvailable(Method method)
{
switch (method)
{

case Method::POSIX_HOSTNAME:
return openPMD_POSIX_AVAILABLE;
case Method::WINSOCKS_HOSTNAME:
return !openPMD_POSIX_AVAILABLE;
case Method::MPI_PROCESSOR_NAME:
return openPMD_HAVE_MPI == 1;
}
Expand All @@ -107,15 +97,13 @@ namespace host_info

std::string byMethod(Method method)
{
static std::map<Method, std::string (*)()> const map{
#ifdef _WIN32
{Method::WINSOCKS_HOSTNAME, &winsocks_hostname}
#else
{Method::POSIX_HOSTNAME, &posix_hostname}
static std::map<Method, std::string (*)()> const map
{
#if openPMD_POSIX_AVAILABLE
{Method::POSIX_HOSTNAME, &posix_hostname},
#endif
#if openPMD_HAVE_MPI
,
{Method::MPI_PROCESSOR_NAME, &mpi_processor_name}
{Method::MPI_PROCESSOR_NAME, &mpi_processor_name},
#endif
};
try
Expand Down Expand Up @@ -162,19 +150,7 @@ namespace host_info
}
#endif

#ifdef _WIN32
std::string winsocks_hostname()
{
char hostname[MAX_HOSTNAME_LENGTH];
if (gethostname(hostname, MAX_HOSTNAME_LENGTH))
{
throw std::runtime_error(
"[winsocks_hostname] Could not inquire hostname.");
}
std::string res(hostname);
return res;
}
#else
#if openPMD_POSIX_AVAILABLE
std::string posix_hostname()
{
char hostname[MAX_HOSTNAME_LENGTH];
Expand All @@ -189,3 +165,5 @@ namespace host_info
#endif
} // namespace host_info
} // namespace openPMD

#undef openPMD_POSIX_AVAILABLE
1 change: 0 additions & 1 deletion src/binding/python/ChunkInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ void init_Chunk(py::module &m)

py::enum_<host_info::Method>(m, "HostInfo")
.value("POSIX_HOSTNAME", host_info::Method::POSIX_HOSTNAME)
.value("WINSOCKS_HOSTNAME", host_info::Method::WINSOCKS_HOSTNAME)
.value("MPI_PROCESSOR_NAME", host_info::Method::MPI_PROCESSOR_NAME)
#if openPMD_HAVE_MPI
.def(
Expand Down
22 changes: 4 additions & 18 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,13 +1534,7 @@ TEST_CASE("dtype_test", "[serial]")
inline void write_test(const std::string &backend)
{
#ifdef _WIN32
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 0), &wsaData);
std::string jsonCfg = R"({"rank_table": "winsocks_hostname"})";
chunk_assignment::RankMeta compare{
{0,
host_info::byMethod(
host_info::methodFromStringDescription("winsocks_hostname"))}};
std::string jsonCfg = "{}";
#else
std::string jsonCfg = R"({"rank_table": "posix_hostname"})";
chunk_assignment::RankMeta compare{
Expand Down Expand Up @@ -1649,11 +1643,8 @@ inline void write_test(const std::string &backend)
o.close();

Series read("../samples/serial_write." + backend, Access::READ_ONLY);
// need double parens here to avoid link errors to unprintableString
// on Windows
REQUIRE((read.mpiRanksMetaInfo(/* collective = */ false) == compare));
#ifdef _WIN32
WSACleanup();
#ifndef _WIN32
REQUIRE(read.mpiRanksMetaInfo(/* collective = */ false) == compare);
#endif
}

Expand Down Expand Up @@ -1810,9 +1801,7 @@ fileBased_add_EDpic(ParticleSpecies &e, uint64_t const num_particles)
inline void fileBased_write_test(const std::string &backend)
{
#ifdef _WIN32
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 0), &wsaData);
std::string jsonCfg = R"({"rank_table": "winsocks_hostname"})";
std::string jsonCfg = "{}";
#else
std::string jsonCfg = R"({"rank_table": "posix_hostname"})";
#endif
Expand Down Expand Up @@ -2196,9 +2185,6 @@ inline void fileBased_write_test(const std::string &backend)
close(dirfd);
}
#endif // defined(__unix__)
#ifdef _WIN32
WSACleanup();
#endif
}

TEST_CASE("fileBased_write_test", "[serial]")
Expand Down

0 comments on commit ff8c373

Please sign in to comment.