Skip to content

Commit a1900c5

Browse files
authored
Merge pull request #12660 from devreal/require-c11
Require C11
2 parents 4d4f721 + e0c2f0b commit a1900c5

File tree

17 files changed

+112
-104
lines changed

17 files changed

+112
-104
lines changed

config/opal_setup_cc.m4

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ AC_DEFUN([OPAL_SETUP_CC],[
170170
AC_REQUIRE([_OPAL_PROG_CC])
171171
AC_REQUIRE([AM_PROG_CC_C_O])
172172

173-
OPAL_VAR_SCOPE_PUSH([opal_prog_cc_c11_helper__Thread_local_available opal_prog_cc_c11_helper_atomic_var_available opal_prog_cc_c11_helper__Atomic_available opal_prog_cc_c11_helper__static_assert_available opal_prog_cc_c11_helper__Generic_available opal_prog_cc__thread_available opal_prog_cc_c11_helper_atomic_fetch_xor_explicit_available opal_prog_cc_c11_helper_proper__Atomic_support_in_atomics])
173+
OPAL_VAR_SCOPE_PUSH([opal_prog_cc_c11_helper__Thread_local_available opal_prog_cc_c11_helper_atomic_var_available opal_prog_cc_c11_helper__Atomic_available opal_prog_cc_c11_helper__static_assert_available opal_prog_cc_c11_helper__Generic_available opal_prog_cc_c11_helper_atomic_fetch_xor_explicit_available opal_prog_cc_c11_helper_proper__Atomic_support_in_atomics])
174174

175175
OPAL_PROG_CC_C11
176176

@@ -179,33 +179,11 @@ AC_DEFUN([OPAL_SETUP_CC],[
179179
OPAL_C_COMPILER_VENDOR([opal_c_vendor])
180180

181181
if test $opal_cv_c11_supported = no ; then
182-
# It is not currently an error if C11 support is not available. Uncomment the
183-
# following lines and update the warning when we require a C11 compiler.
184-
# AC_MSG_WARNING([Open MPI requires a C11 (or newer) compiler])
185-
# AC_MSG_ERROR([Aborting.])
186-
# From Open MPI 1.7 on we require a C99 compliant compiler
187-
dnl with autoconf 2.70 AC_PROG_CC makes AC_PROG_CC_C99 obsolete
188-
m4_version_prereq([2.70],
189-
[],
190-
[AC_PROG_CC_C99])
191-
# The result of AC_PROG_CC_C99 is stored in ac_cv_prog_cc_c99
192-
if test "x$ac_cv_prog_cc_c99" = xno ; then
193-
AC_MSG_WARN([Open MPI requires a C99 (or newer) compiler. C11 is recommended.])
194-
AC_MSG_ERROR([Aborting.])
195-
fi
196-
197-
# Get the correct result for C11 support flags now that the compiler flags have
198-
# changed
199-
OPAL_PROG_CC_C11_HELPER([], [], [])
182+
# C11 is required
183+
AC_MSG_WARN([Open MPI requires a C11 (or newer) compiler. C11 is required.])
184+
AC_MSG_ERROR([Aborting.])
200185
fi
201186

202-
# Check if compiler support __thread
203-
OPAL_CC_HELPER([if $CC $1 supports __thread], [opal_prog_cc__thread_available],
204-
[],[[static __thread int foo = 1;++foo;]])
205-
206-
OPAL_CC_HELPER([if $CC $1 supports C11 _Thread_local], [opal_prog_cc_c11_helper__Thread_local_available],
207-
[],[[static _Thread_local int foo = 1;++foo;]])
208-
209187
dnl At this time Open MPI only needs thread local and the atomic convenience types for C11 support. These
210188
dnl will likely be required in the future.
211189
AC_DEFINE_UNQUOTED([OPAL_C_HAVE__THREAD_LOCAL], [$opal_prog_cc_c11_helper__Thread_local_available],
@@ -223,9 +201,6 @@ AC_DEFUN([OPAL_SETUP_CC],[
223201
AC_DEFINE_UNQUOTED([OPAL_C_HAVE__STATIC_ASSERT], [$opal_prog_cc_c11_helper__static_assert_available],
224202
[Whether C compiler support _Static_assert keyword])
225203

226-
AC_DEFINE_UNQUOTED([OPAL_C_HAVE___THREAD], [$opal_prog_cc__thread_available],
227-
[Whether C compiler supports __thread])
228-
229204
# Check for standard headers, needed here because needed before
230205
# the types checks. This is only necessary for Autoconf < v2.70.
231206
m4_version_prereq([2.70],

docs/developers/prerequisites.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Compilers
55
---------
66

77
Although it should probably be assumed, you'll need a C compiler that
8-
supports C99.
8+
supports C11.
99

1010
You'll also need a Fortran compiler if you want to build the Fortran
1111
MPI bindings (the more recent the Fortran compiler, the better), and a

docs/developers/source-code.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ C / C++
4747
if (whatever)
4848
return OMPI_SUCCESS;
4949
50-
* Starting with Open MPI 1.7, Open MPI requires a C99-compliant
50+
* Starting with Open MPI 6.0, Open MPI requires a C11-compliant
5151
compiler.
5252

5353
* C++-style comments are now allowed (and preferred).

docs/release-notes/changelog/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ since v1.0.0.
88
.. toctree::
99
:maxdepth: 1
1010

11+
v6.0.x
1112
v5.0.x
1213
v4.1.x
1314
v4.0.x
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Open MPI v6.0.x series
2+
======================
3+
4+
This file contains all the NEWS updates for the Open MPI v6.0.x
5+
series, in reverse chronological order.
6+
7+
Open MPI version v6.0.0
8+
--------------------------
9+
:Date: ...fill me in...
10+
11+
- Open MPI now requires a C11-compliant compiler to build.

docs/release-notes/compilers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Compiler Notes
44
==============
55

6-
* Open MPI requires a C99-capable compiler to build.
6+
* Open MPI requires a C11-capable compiler to build.
77

88
* On platforms other than x86-64, AArc64 (64-bit ARM), and PPC, Open
99
MPI requires a compiler that either supports C11 atomics or the GCC

ompi/mca/vprotocol/pessimist/vprotocol_pessimist_wait.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static int vprotocol_pessimist_request_no_free(ompi_request_t **req) {
2020
}
2121

2222
#define PREPARE_REQUESTS_WITH_NO_FREE(count, requests) do { \
23-
for (typeof(count) i = 0; i < count; i++) \
23+
for (size_t i = 0; i < count; i++) \
2424
{ \
2525
if(requests[i] == MPI_REQUEST_NULL) continue; \
2626
requests[i]->req_free = vprotocol_pessimist_request_no_free; \

opal/class/opal_fifo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static inline opal_list_item_t *opal_fifo_pop_atomic(opal_fifo_t *fifo)
224224
if (++attempt == 5) {
225225
/* deliberately suspend this thread to allow other threads to run. this should
226226
* only occur during periods of contention on the lifo. */
227-
_opal_lifo_release_cpu();
227+
opal_lifo_release_cpu();
228228
attempt = 0;
229229
}
230230

opal/class/opal_lifo.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
* $HEADER$
2020
*/
2121

22+
/* needed for nanosleep() */
23+
#define _POSIX_C_SOURCE 200809L
24+
2225
#include "opal_config.h"
26+
#include <time.h>
2327
#include "opal/class/opal_lifo.h"
2428

2529
static void opal_lifo_construct(opal_lifo_t *lifo)
@@ -31,3 +35,16 @@ static void opal_lifo_construct(opal_lifo_t *lifo)
3135
}
3236

3337
OBJ_CLASS_INSTANCE(opal_lifo_t, opal_object_t, opal_lifo_construct, NULL);
38+
39+
40+
void opal_lifo_release_cpu(void)
41+
{
42+
/* NTH: there are many ways to cause the current thread to be suspended. This one
43+
* should work well in most cases. Another approach would be to use poll (NULL, 0, ) but
44+
* the interval will be forced to be in ms (instead of ns or us). Note that there
45+
* is a performance improvement for the lifo test when this call is made on detection
46+
* of contention but it may not translate into actually MPI or application performance
47+
* improvements. */
48+
static struct timespec interval = {.tv_sec = 0, .tv_nsec = 100};
49+
nanosleep(&interval, NULL);
50+
}

opal/class/opal_lifo.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#include "opal_config.h"
3232
#include "opal/class/opal_list.h"
33-
#include <time.h>
3433

3534
#include "opal/mca/threads/mutex.h"
3635
#include "opal/sys/atomic.h"
@@ -92,17 +91,7 @@ opal_read_counted_pointer(volatile opal_counted_pointer_t *volatile addr,
9291
/**
9392
* @brief Helper function for lifo/fifo to sleep this thread if excessive contention is detected
9493
*/
95-
static inline void _opal_lifo_release_cpu(void)
96-
{
97-
/* NTH: there are many ways to cause the current thread to be suspended. This one
98-
* should work well in most cases. Another approach would be to use poll (NULL, 0, ) but
99-
* the interval will be forced to be in ms (instead of ns or us). Note that there
100-
* is a performance improvement for the lifo test when this call is made on detection
101-
* of contention but it may not translate into actually MPI or application performance
102-
* improvements. */
103-
static struct timespec interval = {.tv_sec = 0, .tv_nsec = 100};
104-
nanosleep(&interval, NULL);
105-
}
94+
void opal_lifo_release_cpu(void);
10695

10796
/* Atomic Last In First Out lists. If we are in a multi-threaded environment then the
10897
* atomicity is insured via the compare-and-swap operation, if not we simply do a read
@@ -225,7 +214,7 @@ static inline opal_list_item_t *opal_lifo_pop_atomic(opal_lifo_t *lifo)
225214
if (++attempt == 5) {
226215
/* deliberately suspend this thread to allow other threads to run. this should
227216
* only occur during periods of contention on the lifo. */
228-
_opal_lifo_release_cpu();
217+
opal_lifo_release_cpu();
229218
attempt = 0;
230219
}
231220

opal/mca/threads/pthreads/threads_pthreads_module.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
* $HEADER$
2424
*/
2525

26+
/* needed for pthread_mutexattr_settype */
27+
#define _GNU_SOURCE
28+
2629
#include <unistd.h>
30+
#include <pthread.h>
2731

2832
#include "opal/constants.h"
2933
#include "opal/mca/threads/threads.h"
@@ -38,3 +42,39 @@ int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor)
3842
rc = pthread_key_create(key, destructor);
3943
return 0 == rc ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
4044
}
45+
46+
47+
int opal_thread_internal_mutex_init_recursive(opal_thread_internal_mutex_t *p_mutex)
48+
{
49+
int ret;
50+
#if OPAL_ENABLE_DEBUG
51+
pthread_mutexattr_t mutex_attr;
52+
ret = pthread_mutexattr_init(&mutex_attr);
53+
if (0 != ret)
54+
return OPAL_ERR_IN_ERRNO;
55+
ret = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
56+
if (0 != ret) {
57+
ret = pthread_mutexattr_destroy(&mutex_attr);
58+
assert(0 == ret);
59+
return OPAL_ERR_IN_ERRNO;
60+
}
61+
ret = pthread_mutex_init(p_mutex, &mutex_attr);
62+
if (0 != ret) {
63+
ret = pthread_mutexattr_destroy(&mutex_attr);
64+
assert(0 == ret);
65+
return OPAL_ERR_IN_ERRNO;
66+
}
67+
ret = pthread_mutexattr_destroy(&mutex_attr);
68+
assert(0 == ret);
69+
#else
70+
pthread_mutexattr_t mutex_attr;
71+
ret = pthread_mutexattr_init(&mutex_attr);
72+
if (0 != ret) {
73+
return OPAL_ERR_IN_ERRNO;
74+
}
75+
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
76+
ret = pthread_mutex_init(p_mutex, &mutex_attr);
77+
pthread_mutexattr_destroy(&mutex_attr);
78+
#endif
79+
return 0 == ret ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
80+
}

opal/mca/threads/pthreads/threads_pthreads_mutex.h

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,48 +61,19 @@ typedef pthread_mutex_t opal_thread_internal_mutex_t;
6161
# define OPAL_THREAD_INTERNAL_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER
6262
#endif
6363

64+
65+
int opal_thread_internal_mutex_init_recursive(opal_thread_internal_mutex_t *p_mutex);
66+
6467
static inline int opal_thread_internal_mutex_init(opal_thread_internal_mutex_t *p_mutex,
6568
bool recursive)
6669
{
6770
int ret;
68-
#if OPAL_ENABLE_DEBUG
69-
if (recursive) {
70-
pthread_mutexattr_t mutex_attr;
71-
ret = pthread_mutexattr_init(&mutex_attr);
72-
if (0 != ret)
73-
return OPAL_ERR_IN_ERRNO;
74-
ret = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
75-
if (0 != ret) {
76-
ret = pthread_mutexattr_destroy(&mutex_attr);
77-
assert(0 == ret);
78-
return OPAL_ERR_IN_ERRNO;
79-
}
80-
ret = pthread_mutex_init(p_mutex, &mutex_attr);
81-
if (0 != ret) {
82-
ret = pthread_mutexattr_destroy(&mutex_attr);
83-
assert(0 == ret);
84-
return OPAL_ERR_IN_ERRNO;
85-
}
86-
ret = pthread_mutexattr_destroy(&mutex_attr);
87-
assert(0 == ret);
88-
} else {
89-
ret = pthread_mutex_init(p_mutex, NULL);
90-
}
91-
#else
9271
if (recursive) {
93-
pthread_mutexattr_t mutex_attr;
94-
ret = pthread_mutexattr_init(&mutex_attr);
95-
if (0 != ret) {
96-
return OPAL_ERR_IN_ERRNO;
97-
}
98-
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
99-
ret = pthread_mutex_init(p_mutex, &mutex_attr);
100-
pthread_mutexattr_destroy(&mutex_attr);
72+
return opal_thread_internal_mutex_init_recursive(p_mutex);
10173
} else {
10274
ret = pthread_mutex_init(p_mutex, NULL);
75+
return 0 == ret ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
10376
}
104-
#endif
105-
return 0 == ret ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
10677
}
10778

10879
static inline void opal_thread_internal_mutex_lock(opal_thread_internal_mutex_t *p_mutex)

opal/mca/threads/pthreads/threads_pthreads_yield.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
* $HEADER$
1111
*/
1212

13+
/* needed for nanosleep() */
14+
#define _POSIX_C_SOURCE 200809L
15+
1316
#include "opal_config.h"
1417
#include <time.h>
1518
#ifdef HAVE_SCHED_H

opal/mca/threads/thread_usage.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,7 @@ OPAL_THREAD_DEFINE_ATOMIC_SWAP(int64_t, int64_t, 64)
250250
# define OPAL_ATOMIC_SWAP_64 opal_thread_swap_64
251251

252252
/* thread local storage */
253-
#if OPAL_C_HAVE__THREAD_LOCAL
254253
# define opal_thread_local _Thread_local
255254
# define OPAL_HAVE_THREAD_LOCAL 1
256255

257-
#elif OPAL_C_HAVE___THREAD /* OPAL_C_HAVE__THREAD_LOCAL */
258-
# define opal_thread_local __thread
259-
# define OPAL_HAVE_THREAD_LOCAL 1
260-
#endif /* OPAL_C_HAVE___THREAD */
261-
262-
#if !defined(OPAL_HAVE_THREAD_LOCAL)
263-
# define OPAL_HAVE_THREAD_LOCAL 0
264-
#endif /* !defined(OPAL_HAVE_THREAD_LOCAL) */
265-
266256
#endif /* OPAL_MCA_THREADS_THREAD_USAGE_H */

opal/util/Makefile.am

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ libopalutil_core_la_DEPENDENCIES = \
138138
json/libopalutil_json.la \
139139
keyval/libopalutilkeyval.la
140140

141+
# flex prior to version 2.6.6 uses the POSIX extension fileno()
142+
# without providing the proper feature test macro, so
143+
# we add the _POSIX_C_SOURCE macro here.
144+
# See https://github.com/westes/flex/issues/263
145+
libopalutil_core_la_CFLAGS = -D_POSIX_C_SOURCE=200809L
146+
141147
# Conditionally install the header files
142148

143149
if WANT_INSTALL_HEADERS

opal/util/keyval/Makefile.am

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,11 @@ libopalutilkeyval_la_SOURCES = \
3030
keyval_lex.h \
3131
keyval_lex.l
3232

33+
# flex prior to version 2.6.6 uses the POSIX extension fileno()
34+
# without providing the proper feature test macro, so
35+
# we add the _POSIX_C_SOURCE macro here.
36+
# See https://github.com/westes/flex/issues/263
37+
libopalutilkeyval_la_CFLAGS = -D_POSIX_C_SOURCE=200809L
38+
3339
maintainer-clean-local:
3440
rm -f keyval_lex.c

test/datatype/reduce_local.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@
55
* reserved.
66
* Copyright (c) 2020 Research Organization for Information Science
77
* and Technology (RIST). All rights reserved.
8+
* Copyright (c) 2024 Stony Brook University. All rights reserved.
89
* $COPYRIGHT$
910
*
1011
* Additional copyrights may follow
1112
*
1213
* $HEADER$
1314
*/
1415

16+
/* needed for strsep() */
17+
#define _DEFAULT_SOURCE
18+
#define _BSD_SOURCE
19+
20+
/* needed for posix_memalign() and getopt() */
21+
#define _POSIX_C_SOURCE 200809L
22+
23+
#include "ompi_config.h"
1524
#include <stdbool.h>
1625
#include <stdint.h>
1726
#include <stdio.h>
@@ -50,19 +59,9 @@ static int do_ops[12] = {
5059
static int verbose = 0;
5160
static int total_errors = 0;
5261

53-
#define max(a, b) \
54-
({ \
55-
__typeof__(a) _a = (a); \
56-
__typeof__(b) _b = (b); \
57-
_a > _b ? _a : _b; \
58-
})
59-
60-
#define min(a, b) \
61-
({ \
62-
__typeof__(a) _a = (a); \
63-
__typeof__(b) _b = (b); \
64-
_a < _b ? _a : _b; \
65-
})
62+
#define max(a, b) (a) > (b) ? (a) : (b)
63+
64+
#define min(a, b) (a) < (b) ? (a) : (b)
6665

6766
static void print_status(char *op, char *type, int type_size, int count, int max_shift,
6867
double *duration, int repeats, int correct)

0 commit comments

Comments
 (0)