Skip to content

Commit

Permalink
inet_network does not exist on Windows, so replace htonl(inet_network…
Browse files Browse the repository at this point in the history
…(c)) with inet_addr(c). Verified that it gives the same result with the code,

int main(int argc, char** argv) {
  MPI_Init(&argc, &argv);
  char hostname[MPI_MAX_PROCESSOR_NAME];
  int len;
  MPI_Get_processor_name(hostname,&len);
  struct hostent * host = gethostbyname(hostname);
  int myaddr1 = (int) inet_addr(inet_ntoa(*(struct in_addr *)host->h_addr));
  int myaddr2 = (int) htonl(inet_network(inet_ntoa(*(struct in_addr *)host->h_addr)));
  std::cout << "myaddr1 = " << myaddr1 << std::endl;
  std::cout << "myaddr2 = " << myaddr2 << std::endl;
  MPI_Finalize();
}

Compiled with

  mpicxx testinet.cxx -o testinet

Output was

cary@kara/.../~$ mpiexec -np 1 testinet
myaddr1 = -285103936
myaddr2 = -285103936
  • Loading branch information
jrobcary committed May 28, 2021
1 parent 0601dde commit a53f6a4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/muelu/src/Utils/MueLu_Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@

#ifdef HAVE_MPI
#include <mpi.h>
#ifdef _WIN32
#include <winsock2.h>
#else
#include <netdb.h>
#include <arpa/inet.h>
#endif
#endif



Expand Down Expand Up @@ -265,7 +269,7 @@ bool IsParamValidVariable(const std::string& name)
int len;
MPI_Get_processor_name(hostname,&len);
struct hostent * host = gethostbyname(hostname);
int myaddr = (int) htonl(inet_network(inet_ntoa(*(struct in_addr *)host->h_addr)));
int myaddr = (int) inet_addr(inet_ntoa(*(struct in_addr *)host->h_addr));

// All-to-all exchange of address integers
std::vector<int> addressList(numRanks);
Expand Down

0 comments on commit a53f6a4

Please sign in to comment.