Skip to content

Commit 520b8aa

Browse files
authored
Merge pull request #295 from bonachea/thread-safety
Add thread-safe library build and deploy thread-safety mechanisms where appropriate
2 parents a02c7dd + d65106b commit 520b8aa

21 files changed

Lines changed: 387 additions & 68 deletions

.github/workflows/build.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ jobs:
315315
echo SUBJOB_PREFIX=${SUBJOB_PREFIX}
316316
while (( CAF_IMAGES > 0 )); do \
317317
echo CAF_IMAGES=${CAF_IMAGES} ; \
318-
( set -x ; ./run-fpm.sh test --verbose -- -d ) ; \
318+
( set -x ; ./run-fpm.sh test --verbose -- ) ; \
319319
sleep 1 ; \
320320
CAF_IMAGES=$(( CAF_IMAGES / 2 )) ; \
321321
done
@@ -350,3 +350,11 @@ jobs:
350350
) ; \
351351
done
352352
353+
- name: Build and Test Caffeine (thread-safe)
354+
run: |
355+
for var in FC CC CXX FFLAGS CPPFLAGS CFLAGS LDFLAGS LIBS GASNET_CONFIGURE_ARGS ; do \
356+
eval echo "$var=\$$var"; done
357+
set -x
358+
./install.sh --prefix=${PREFIX} --network=${{ matrix.network }} --enable-threads --verbose
359+
./run-fpm.sh test --verbose --
360+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ to ensure that a matching set of LLVM compilers are used.
115115

116116
The `install.sh` recognizes a number of command-line options and environment variables to
117117
customize behavior for your system. See the output of `./install.sh --help` for full documentation,
118-
including options for how to build for a distributed-memory platform.
118+
including options for how to build for a distributed-memory platform or with thread-safety.
119119

120120

121121
Example Usage

docs/README-release.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ Release Procedure for Caffeine
1212
1. Update all instances of the copyright year embedded in: [LICENSE.txt](../LICENSE.txt),
1313
[manifest/fpm.toml.template](../manifest/fpm.toml.template)
1414
2. Update all instances of the release package version number embedded in:
15-
[manifest/fpm.toml.template](../manifest/fpm.toml.template), [install.sh](../install.sh)
15+
[manifest/fpm.toml.template](../manifest/fpm.toml.template), [install.sh](../install.sh), [version.h](../include/version.h)
1616
3. Update the author list embedded in: [manifest/fpm.toml.template](../manifest/fpm.toml.template)
1717
4. Review top-level [README.md](../README.md) and other user-facing documentation for any
1818
necessary changes
1919
5. Update [docs/implementation-status.md](../docs/implementation-status.md) with current status
2020
6. If the PRIF specification revision is changing, search and update all instances of the old revision,
21-
including `CAF_PRIF_VERSION_{MAJOR,MINOR}` in [language-support.F90](../include/language-support.F90)
21+
including `CAF_PRIF_VERSION_{MAJOR,MINOR}` in [version.h](../include/version.h)
2222
7. Temporarily hardcode version of gasnet installer in [install.sh](../install.sh) as the
2323
last commit in the release. Set GASNET_VERSION flag to the latest gasnet release
2424
5. Produce the ChangeLog
@@ -42,7 +42,7 @@ Release Procedure for Caffeine
4242
10. Post release chores
4343
1. Git revert the commit that hardcoded the gasnet version or manually edit
4444
2. Update patch number of the version number embedded in:
45-
[manifest/fpm.toml.template](../manifest/fpm.toml.template), [install.sh](../install.sh)
45+
[manifest/fpm.toml.template](../manifest/fpm.toml.template), [install.sh](../install.sh), [version.h](../include/version.h)
4646
Update to an odd number to indicate that the `main` branch is currently a snapshot of something
4747
that is beyond the offical release
4848
3. Update the release procedure with any new steps or changes

include/language-support.F90

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,4 @@
7070
#define CAF_IMPORT_TEAM_CONSTANTS CAF_IMPORT_CONSTANTS
7171
#endif
7272

73-
! PRIF specification version override and control
74-
! By default, Caffeine provides the latest ratified version of the PRIF specification.
75-
! Clients can optionally define one of the FORCE_* macros below to force compliance
76-
! with a different revision of the PRIF specification. These override settings are
77-
! NOT officially supported and may be removed at any time without notice.
78-
#define CAF_PRIF_VERSION_MAJOR 0
79-
#if FORCE_PRIF_0_5
80-
# define CAF_PRIF_VERSION_MINOR 5
81-
#elif FORCE_PRIF_0_6
82-
# define CAF_PRIF_VERSION_MINOR 6
83-
#elif FORCE_PRIF_0_7
84-
# define CAF_PRIF_VERSION_MINOR 7
85-
#elif FORCE_PRIF_0_8
86-
# define CAF_PRIF_VERSION_MINOR 8
87-
#else
88-
# define CAF_PRIF_VERSION_MINOR 7
89-
#endif
90-
#define CAF_PRIF_VERSION (100 * CAF_PRIF_VERSION_MAJOR + CAF_PRIF_VERSION_MINOR)
91-
9273
#endif

include/version.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# /* Copyright (c), The Regents of the University of California */
2+
# /* Terms of use are as specified in LICENSE.txt */
3+
4+
# /* NOTE: this is a dual-language header file, */
5+
# /* and should ONLY contain portable preprocessor directives. */
6+
7+
#ifndef CAF_INCLUDED_VERSION_H
8+
#define CAF_INCLUDED_VERSION_H
9+
10+
# /* Caffeine software package versioning */
11+
#define CAF_RELEASE_VERSION_MAJOR 0
12+
#define CAF_RELEASE_VERSION_MINOR 7
13+
#define CAF_RELEASE_VERSION_PATCH 1
14+
#define CAF_RELEASE_VERSION (1000*CAF_RELEASE_VERSION_MAJOR + 100*CAF_RELEASE_VERSION_MINOR + CAF_RELEASE_VERSION_PATCH)
15+
16+
#if 0
17+
! PRIF specification version override and control
18+
! By default, Caffeine provides the latest ratified version of the PRIF specification.
19+
! Clients can optionally define one of the FORCE_* macros below to force compliance
20+
! with a different revision of the PRIF specification. These override settings are
21+
! NOT officially supported and may be removed at any time without notice.
22+
#endif
23+
#define CAF_PRIF_VERSION_MAJOR 0
24+
#if FORCE_PRIF_0_5
25+
# define CAF_PRIF_VERSION_MINOR 5
26+
#elif FORCE_PRIF_0_6
27+
# define CAF_PRIF_VERSION_MINOR 6
28+
#elif FORCE_PRIF_0_7
29+
# define CAF_PRIF_VERSION_MINOR 7
30+
#elif FORCE_PRIF_0_8
31+
# define CAF_PRIF_VERSION_MINOR 8
32+
#else
33+
# define CAF_PRIF_VERSION_MINOR 7
34+
#endif
35+
#define CAF_PRIF_VERSION (100 * CAF_PRIF_VERSION_MAJOR + CAF_PRIF_VERSION_MINOR)
36+
37+
#endif

install.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ USAGE:
2323
Default prefix='\$HOME/.local/bin'
2424
--verbose Show verbose build commands
2525
--yes Assume (yes) to all prompts for non-interactive build
26+
--enable-threads Build a thread-safe Caffeine library and link to
27+
thread-safe GASNet, for use in threaded do-concurrent.
2628
2729
All unrecognized arguments will be passed to GASNet's configure.
2830
@@ -48,6 +50,7 @@ EOF
4850
GASNET_VERSION="stable"
4951
VERBOSE=""
5052
GASNET_CONDUIT="${GASNET_CONDUIT:-smp}"
53+
GASNET_THREADMODE="${GASNET_THREADMODE:-seq}"
5154
YES=false
5255
APPEND_CFLAGS=""
5356

@@ -106,6 +109,9 @@ while [ "$1" != "" ]; do
106109
-y | --yes)
107110
YES="true"
108111
;;
112+
--enable-threads) GASNET_THREADMODE=par ;;
113+
--disable-threads) GASNET_THREADMODE=seq ;;
114+
109115
*)
110116
# We pass the unmodified argument to GASNet configure
111117
# Quoting is believed sufficient for embedded whitespace but not quotes
@@ -382,7 +388,7 @@ EOF
382388
printf "Is it ok to download and install $1? [yes] "
383389
}
384390

385-
pkg="gasnet-$GASNET_CONDUIT-seq"
391+
pkg="gasnet-$GASNET_CONDUIT-$GASNET_THREADMODE"
386392
export PKG_CONFIG_PATH
387393

388394
if ! $PKG_CONFIG $pkg ; then
@@ -411,7 +417,7 @@ if ! $PKG_CONFIG $pkg ; then
411417
cmd="$cmd --with-cc=\"$CC\" --with-cxx=\"$CXX\""
412418
# select the GASNet config settings Caffeine requires, and disable unused features:
413419
cmd="$cmd --enable-$GASNET_CONDUIT"
414-
cmd="$cmd --enable-seq --disable-par --disable-parsync"
420+
cmd="$cmd --enable-seq --enable-par --disable-parsync"
415421
cmd="$cmd --disable-segment-everything"
416422
# TEMPORARY: disable MPI compatibility until we figure out how to support in fpm
417423
cmd="$cmd --disable-mpi-compat"
@@ -522,6 +528,10 @@ if ! [[ "$user_compiler_flags " =~ -[DU]ASSERTIONS[=\ ] ]] ; then
522528
compiler_flag+=" -DASSERTIONS"
523529
fi
524530

531+
if [[ $GASNET_THREADMODE == "par" ]] ; then
532+
compiler_flag+=" -DCAF_THREAD_SAFE"
533+
fi
534+
525535
GASNET_CONDUIT_UPPER=$(tr '[:lower:]' '[:upper:]' <<<$GASNET_CONDUIT)
526536
compiler_flag+=" -DCAF_NETWORK_$GASNET_CONDUIT_UPPER"
527537

@@ -584,7 +594,7 @@ chmod u+x $RUN_FPM_SH
584594

585595
./$RUN_FPM_SH build $VERBOSE
586596

587-
LIBCAFFEINE_DST=libcaffeine-$GASNET_CONDUIT.a
597+
LIBCAFFEINE_DST=libcaffeine-$GASNET_CONDUIT-$GASNET_THREADMODE.a
588598
LIBCAFFEINE_SRC=$(./$RUN_FPM_SH install --list 2>/dev/null | grep libcaffeine | cut -d' ' -f2)
589599

590600
if [ -z "$LIBCAFFEINE_SRC" ]; then
@@ -593,6 +603,7 @@ if [ -z "$LIBCAFFEINE_SRC" ]; then
593603
else
594604
mkdir -p "$PREFIX/lib"
595605
cp -af "$LIBCAFFEINE_SRC" "$PREFIX/lib/$LIBCAFFEINE_DST"
606+
ln -sf "$LIBCAFFEINE_DST" "$PREFIX/lib/libcaffeine-$GASNET_CONDUIT.a"
596607
ln -sf "$LIBCAFFEINE_DST" "$PREFIX/lib/libcaffeine.a"
597608
fi
598609

src/caffeine/alias_s.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
! Terms of use are as specified in LICENSE.txt
33

44
#include "assert_macros.h"
5-
#include "language-support.F90"
5+
#include "version.h"
66

77
submodule(prif:prif_private_s) alias_s
88
! DO NOT ADD USE STATEMENTS HERE

src/caffeine/allocation_s.F90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
! Terms of use are as specified in LICENSE.txt
33

44
#include "assert_macros.h"
5+
#include "version.h"
56
#include "language-support.F90"
67

78
submodule(prif:prif_private_s) allocation_s
@@ -99,7 +100,7 @@
99100
module procedure prif_allocate
100101
type(c_ptr) :: mem
101102

102-
mem = caf_allocate(non_symmetric_heap_mspace, size_in_bytes)
103+
mem = caf_allocate_non_symmetric(size_in_bytes)
103104
if (.not. c_associated(mem)) then
104105
call report_error(PRIF_STAT_OUT_OF_MEMORY, out_of_memory_message(size_in_bytes, .false.), &
105106
stat, errmsg, errmsg_alloc)
@@ -215,7 +216,7 @@ subroutine coarray_cleanup_i(handle, stat, errmsg) bind(C)
215216
end procedure
216217

217218
module procedure prif_deallocate
218-
call caf_deallocate(non_symmetric_heap_mspace, mem)
219+
call caf_deallocate_non_symmetric(mem)
219220
if (present(stat)) stat = 0
220221
end procedure
221222

src/caffeine/caffeine-internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# /* NOTE: this is a dual-language header file, */
55
# /* and should ONLY contain portable preprocessor directives. */
66

7+
#ifndef CAF_INCLUDED_CAFFEINE_INTERNAL_H
8+
#define CAF_INCLUDED_CAFFEINE_INTERNAL_H
9+
710
# /* define some macro portability helpers */
811
#if defined(__GFORTRAN__) || defined(_CRAYFTN) || defined(NAGFOR)
912
# define CAF_CONCAT2(x,y) x/**/y
@@ -30,3 +33,4 @@
3033
#define CAF_OP_FXOR 9
3134
#define CAF_OP_FCAS 10
3235

36+
#endif

0 commit comments

Comments
 (0)