Skip to content

Commit

Permalink
9184 winllvmparbuild: fix winllvm parallel builds with modification t…
Browse files Browse the repository at this point in the history
…o muelu, zoltan2, belos (#9187)

* C++ proscribes using addressof to return a constexpr, and this is
enforced by LLVM-11, at least on Windows.  The workaround is described at

https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas

So implemented.

* For Windows added:

  typedef SSIZE_T ssize_t;

in core/src/input/Zoltan2_InputTraits.hpp.

Fixed the sys/time.h versus time.h in

zoltan2/core/src/algorithms/color/Zoltan2_AlgHybrid2GL.hpp
zoltan2/core/src/algorithms/color/Zoltan2_AlgHybridD1-2GL.hpp
zoltan2/core/src/algorithms/color/Zoltan2_AlgHybridD1.hpp
zoltan2/core/src/algorithms/color/Zoltan2_AlgHybridD2.hpp
zoltan2/core/src/algorithms/color/Zoltan2_AlgHybridPD2.hpp
zoltan2/core/src/input/Zoltan2_InputTraits.hpp

* inet_network does not exist on Windows, so replace htonl(inet_network(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

Co-authored-by: Jared Popelar <[email protected]>
  • Loading branch information
jrobcary and Jared Popelar authored Jun 10, 2021
1 parent 64c033e commit 39e7b27
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/belos/src/BelosBiCGStabSolMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,13 @@ namespace Belos {
static constexpr int defQuorum_default_ = 1;
static constexpr const char * resScale_default_ = "Norm of Initial Residual";
static constexpr const char * label_default_ = "Belos";
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif

// Current solver values.
MagnitudeType convtol_,achievedTol_;
Expand Down
6 changes: 6 additions & 0 deletions packages/belos/src/BelosBlockCGSolMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,13 @@ namespace Belos {
static constexpr const char * label_default_ = "Belos";
static constexpr const char * orthoType_default_ = "ICGS";
static constexpr bool assertPositiveDefiniteness_default_ = true;
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif

//
// Current solver parameters and other values.
Expand Down
8 changes: 7 additions & 1 deletion packages/belos/src/BelosBlockGmresSolMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,13 @@ class BlockGmresSolMgr : public SolverManager<ScalarType,MV,OP> {
static constexpr const char * expResScale_default_ = "Norm of Initial Residual";
static constexpr const char * label_default_ = "Belos";
static constexpr const char * orthoType_default_ = "ICGS";
static constexpr std::ostream * outputStream_default_ = &std::cout;
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif

// Current solver values.
MagnitudeType convtol_, orthoKappa_, achievedTol_;
Expand Down
6 changes: 6 additions & 0 deletions packages/belos/src/BelosFixedPointSolMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,13 @@ namespace Belos {
static constexpr int outputStyle_default_ = Belos::General;
static constexpr int outputFreq_default_ = -1;
static constexpr const char * label_default_ = "Belos";
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif

//
// Current solver parameters and other values.
Expand Down
6 changes: 6 additions & 0 deletions packages/belos/src/BelosGCRODRSolMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,13 @@ Systems," SIAM Journal on Scientific Computing, 28(5), pp. 1651-1674,
static constexpr const char * expResScale_default_ = "Norm of Initial Residual";
static constexpr const char * label_default_ = "Belos";
static constexpr const char * orthoType_default_ = "ICGS";
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif

// Current solver values.
MagnitudeType convTol_, orthoKappa_, achievedTol_;
Expand Down
6 changes: 6 additions & 0 deletions packages/belos/src/BelosGmresPolyOp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,13 @@ namespace Belos {
static constexpr const char * label_default_ = "Belos";
static constexpr const char * polyType_default_ = "Roots";
static constexpr const char * orthoType_default_ = "DGKS";
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif
static constexpr bool damp_default_ = false;
static constexpr bool addRoots_default_ = true;

Expand Down
8 changes: 7 additions & 1 deletion packages/belos/src/BelosGmresPolySolMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,13 @@ class GmresPolySolMgr : public SolverManager<ScalarType,MV,OP> {
static constexpr bool addRoots_default_ = true;
static constexpr bool dampPoly_default_ = false;
static constexpr bool randomRHS_default_ = true;
static constexpr std::ostream * outputStream_default_ = &std::cout;
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif

// Current solver values.
MagnitudeType polyTol_;
Expand Down
6 changes: 6 additions & 0 deletions packages/belos/src/BelosPCPGSolMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,13 @@ namespace Belos {
static constexpr int outputFreq_default_ = -1;
static constexpr const char * label_default_ = "Belos";
static constexpr const char * orthoType_default_ = "ICGS";
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif

//
// Current solver values.
Expand Down
6 changes: 6 additions & 0 deletions packages/belos/src/BelosPseudoBlockCGSolMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,13 @@ namespace Belos {
static constexpr bool foldConvergenceDetectionIntoAllreduce_default_ = false;
static constexpr const char * resScale_default_ = "Norm of Initial Residual";
static constexpr const char * label_default_ = "Belos";
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif
static constexpr bool genCondEst_default_ = false;

// Current solver values.
Expand Down
6 changes: 6 additions & 0 deletions packages/belos/src/BelosPseudoBlockGmresSolMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,13 @@ namespace Belos {
static constexpr const char * expResScale_default_ = "Norm of Initial Residual";
static constexpr const char * label_default_ = "Belos";
static constexpr const char * orthoType_default_ = "ICGS";
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif

// Current solver values.
MagnitudeType convtol_, orthoKappa_, achievedTol_;
Expand Down
6 changes: 6 additions & 0 deletions packages/belos/src/BelosPseudoBlockStochasticCGSolMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,13 @@ namespace Belos {
static constexpr int defQuorum_default_ = 1;
static constexpr const char * resScale_default_ = "Norm of Initial Residual";
static constexpr const char * label_default_ = "Belos";
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif

// Current solver values.
MagnitudeType convtol_;
Expand Down
6 changes: 6 additions & 0 deletions packages/belos/src/BelosPseudoBlockTFQMRSolMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,13 @@ namespace Belos {
static constexpr const char * impResScale_default_ = "Norm of Preconditioned Initial Residual";
static constexpr const char * expResScale_default_ = "Norm of Initial Residual";
static constexpr const char * label_default_ = "Belos";
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif

// Current solver values.
MagnitudeType convtol_, impTolScale_, achievedTol_;
Expand Down
6 changes: 6 additions & 0 deletions packages/belos/src/BelosRCGSolMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,13 @@ namespace Belos {
static constexpr int outputStyle_default_ = Belos::General;
static constexpr int outputFreq_default_ = -1;
static constexpr const char * label_default_ = "Belos";
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif

//
// Current solver values.
Expand Down
6 changes: 6 additions & 0 deletions packages/belos/src/BelosTFQMRSolMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,13 @@ namespace Belos {
static constexpr const char * impResScale_default_ = "Norm of Preconditioned Initial Residual";
static constexpr const char * expResScale_default_ = "Norm of Initial Residual";
static constexpr const char * label_default_ = "Belos";
// https://stackoverflow.com/questions/24398102/constexpr-and-initialization-of-a-static-const-void-pointer-with-reinterpret-cas
#if defined(_WIN32) && defined(__clang__)
static constexpr std::ostream * outputStream_default_ =
__builtin_constant_p(reinterpret_cast<const std::ostream*>(&std::cout));
#else
static constexpr std::ostream * outputStream_default_ = &std::cout;
#endif

// Current solver values.
MagnitudeType convtol_, impTolScale_, achievedTol_;
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include <unordered_map>
#include <iostream>
#include <queue>
#ifdef _WIN32
#include <time.h>
#else
#include <sys/time.h>
#endif

#include "Zoltan2_Algorithm.hpp"
#include "Zoltan2_GraphModel.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include <unordered_map>
#include <iostream>
#include <queue>
#ifdef _WIN32
#include <time.h>
#else
#include <sys/time.h>
#endif

#include "Zoltan2_Algorithm.hpp"
#include "Zoltan2_GraphModel.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
#include <iostream>
#include <fstream>
#include <queue>
#ifdef _WIN32
#include <time.h>
#else
#include <sys/time.h>
#endif
#include <algorithm>

#include "Zoltan2_Algorithm.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include <unordered_map>
#include <iostream>
#include <queue>
#ifdef _WIN32
#include <time.h>
#else
#include <sys/time.h>
#endif

#include "Zoltan2_Algorithm.hpp"
#include "Zoltan2_GraphModel.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include <unordered_map>
#include <iostream>
#include <queue>
#ifdef _WIN32
#include <time.h>
#else
#include <sys/time.h>
#endif

#include "Zoltan2_Algorithm.hpp"
#include "Zoltan2_GraphModel.hpp"
Expand Down
4 changes: 4 additions & 0 deletions packages/zoltan2/core/src/input/Zoltan2_InputTraits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ struct InputTraits {

#ifndef DOXYGEN_SHOULD_SKIP_THIS

#ifdef _MSC_VER
typedef SSIZE_T ssize_t;
#endif

// This combination of macros is used to define a single line
// Z2_STATIC_ASSERT_TYPES for each InputTraits with custom template types
#define Z2_ISSAME(s,type) (std::is_same< s, type >::value)
Expand Down

0 comments on commit 39e7b27

Please sign in to comment.