Skip to content

Commit 6531616

Browse files
patching MPICH preprocessors
and added a warning about a potential issue with v3.X MPICH compilers. Also added code warnings that MSVC does not support the `#warning` pragma (ridiculous!)
1 parent 5ca3daa commit 6531616

File tree

6 files changed

+33
-41
lines changed

6 files changed

+33
-41
lines changed

quest/include/deprecated.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@
3030

3131
#if !defined(DISABLE_DEPRECATION_WARNINGS) || DISABLE_DEPRECATION_WARNINGS == 0
3232

33-
#warning \
34-
"Deprecated functions have been included in compilation. The QuEST v3 API will be attemptedly \
35-
automatically substituted for the v4 API, although some uses of the old API will still fail to \
36-
compile. For example, access to v3 struct fields (e.g. 'ComplexMatrixN.real[0][0]') must be \
37-
manually replaced with v4 struct fields (e.g. 'CompMatr.cpuElems[0][0]'), though new v4 functions \
38-
make struct field access mostly redundant (e.g. via 'setCompMatr()'). Even when successfully \
39-
compiling, use of the deprecated v3 functions is dangerous; these are not unit-tested, and the \
40-
auto-porting to v4 may introduce new bugs. As such, you should only use this facility to help \
41-
refactor your code to v4, and should absolutely not continue to use the old v3 API for simulation."
33+
// #warning command is always recognised (deprecated API is not MSVC-compatible)
34+
#warning "\
35+
Deprecated functions have been included in compilation. The QuEST v3 API will be attemptedly \
36+
automatically substituted for the v4 API, although some uses of the old API will still fail to \
37+
compile. For example, access to v3 struct fields (e.g. 'ComplexMatrixN.real[0][0]') must be \
38+
manually replaced with v4 struct fields (e.g. 'CompMatr.cpuElems[0][0]'), though new v4 functions \
39+
make struct field access mostly redundant (e.g. via 'setCompMatr()'). Even when successfully \
40+
compiling, use of the deprecated v3 functions is dangerous; these are not unit-tested, and the \
41+
auto-porting to v4 may introduce new bugs. As such, you should only use this facility to help \
42+
refactor your code to v4, and should absolutely not continue to use the old v3 API for simulation."
4243

4344
#endif
4445

quest/src/comm/comm_config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#ifdef OPEN_MPI
3535
#include <mpi-ext.h>
3636

37+
// #warning command is always recognised (OpenMPI is not Windows compatible)
3738
#ifndef MPIX_CUDA_AWARE_SUPPORT
3839
#warning "Could not ascertain whether MPI is CUDA-aware, so we will assume it is not. This means inter-GPU communication will be slowly routed through the CPU/RAM."
3940
#elif !MPIX_CUDA_AWARE_SUPPORT
@@ -42,6 +43,8 @@
4243
#endif
4344

4445
/// @todo check whether MPICH is CUDA-aware
46+
/// beware MSVC cannot parse #warning, and
47+
/// Intel MPI would crash (but not MSMPI?)
4548

4649
#endif
4750

quest/src/comm/comm_routines.cpp

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -101,45 +101,30 @@ qindex MAX_MESSAGE_LENGTH = powerOf2(28);
101101

102102
#if COMPILE_MPI
103103

104-
// declare MPI type for qreal
105-
#if (FLOAT_PRECISION == 1)
106-
#define MPI_QREAL MPI_FLOAT
107-
#elif (FLOAT_PRECISION == 2)
108-
#define MPI_QREAL MPI_DOUBLE
109-
#elif (FLOAT_PRECISION == 4)
110-
#define MPI_QREAL MPI_LONG_DOUBLE
104+
// warn about strange behaviour on MPICH v3.X
105+
#ifdef MPICH
106+
#if MPI_VERSION < 4
107+
// accursed Windows users get no warning (MSVC doesn't support #warning)
108+
#ifndef _MSC_VER
109+
#warning "Using MPICH versions earlier than 4.0 may result in errors. Please run the distributed unit tests."
110+
#endif
111+
#endif
111112
#endif
112113

113-
/// @todo:
114-
/// below is failing on ARCHER2 MPICH (depsite working on
115-
/// other MPICH versions) because it defines the unsupported
116-
/// preprocessors to be MPI_DATATYPE_NULL, as per:
117-
/// https://trac.macports.org/ticket/71266. So below, we are
118-
/// choosing to e.g. set MPI_QCOMP = MPI_CXX_DOUBLE_COMPLEX =
119-
/// MPI_DATATYPE_NULL, which then fails at runtime. In lieu
120-
/// of determining which MPICH versions do this, we presently
121-
/// simply avoid the CXX macros altogether on MPICH.
122-
123-
// declare MPI type for qcomp, falling back to C types
124-
// when the C++ type does not exist, as is the case for
125-
// MS MPI and other compilers at quad precision
126-
#if (FLOAT_PRECISION == 1) && defined(MPI_CXX_FLOAT_COMPLEX) && !defined(MPICH)
127-
#define MPI_QCOMP MPI_CXX_FLOAT_COMPLEX
128-
#elif (FLOAT_PRECISION == 1)
114+
// declare MPI types for qreal and qcomp. We always use the
115+
// C macros, even when the deprecated CXX equivalents are
116+
// available, to maintain compatibility with modern MPICH
117+
#if (FLOAT_PRECISION == 1)
118+
#define MPI_QREAL MPI_FLOAT
129119
#define MPI_QCOMP MPI_C_FLOAT_COMPLEX
130-
131-
#elif (FLOAT_PRECISION == 2) && defined(MPI_CXX_DOUBLE_COMPLEX) && !defined(MPICH)
132-
#define MPI_QCOMP MPI_CXX_DOUBLE_COMPLEX
133120
#elif (FLOAT_PRECISION == 2)
121+
#define MPI_QREAL MPI_DOUBLE
134122
#define MPI_QCOMP MPI_C_DOUBLE_COMPLEX
135-
136-
#elif (FLOAT_PRECISION == 4) && defined(MPI_CXX_LONG_DOUBLE_COMPLEX) && !defined(MPICH)
137-
#define MPI_QCOMP MPI_CXX_LONG_DOUBLE_COMPLEX
138123
#elif (FLOAT_PRECISION == 4)
124+
#define MPI_QREAL MPI_LONG_DOUBLE
139125
#define MPI_QCOMP MPI_C_LONG_DOUBLE_COMPLEX
140-
141126
#else
142-
#error "Something went horribly wrong in inferring the MPI type"
127+
#error "Something went horribly wrong in inferring the MPI types"
143128
#endif
144129

145130
#endif

quest/src/core/inliner.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#define INLINE inline __attribute__((always_inline))
5252

5353
#else
54+
55+
// #warning command safe in non-MSVC compiler
5456
#warning "Could not ascertain compiler type in order to choose the correct inline attribute. Assuming GNU and proceeding..."
5557
#define INLINE inline __attribute__((always_inline))
5658

quest/src/core/printer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ int printer_getNumTrailingNewlines() {
155155
// fall-back to dangerous compiler-specific check (we know MSVC doesn't mangle)
156156
#elif ! defined _MSC_VER
157157

158+
// #warning command safe in non-MSVC compiler
158159
#warning "Attempting to include compiler-specific library <cxxabi.h>"
159160

160161
#include <cxxabi.h>

tests/deprecated/test_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <stdexcept>
2828

2929

30-
/** Redefinition of QuEST_validation's invalidQuESTInputError function, called when a
30+
/* Redefinition of QuEST_validation's invalidQuESTInputError function, called when a
3131
* user passes an incorrect parameter (e.g. a negative qubit index). This is
3232
* redefined here to, in lieu of printing and exiting, throw a C++ exception
3333
* which can be caught (and hence unit tested for) by Catch2

0 commit comments

Comments
 (0)