Skip to content

Commit 7fba091

Browse files
author
Damian Rouson
authored
Merge pull request #491 from sourceryinstitute/descriptor-surgery
Adjust for the Fortran 2018 descriptors
2 parents 4cc41bf + 4cafd03 commit 7fba091

File tree

6 files changed

+73
-17
lines changed

6 files changed

+73
-17
lines changed

src/libcaf-gfortran-descriptor.h

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
2828
#ifndef LIBCAF_GFORTRAN_DESCRIPTOR_H
2929
#define LIBCAF_GFORTRAN_DESCRIPTOR_H
3030

31+
#include "libcaf-version-def.h"
32+
3133
#include <stdint.h> /* For int32_t. */
3234

3335
/* GNU Fortran's array descriptor. Keep in sync with libgfortran.h. To be
@@ -47,34 +49,64 @@ typedef struct descriptor_dimension
4749
}
4850
descriptor_dimension;
4951

52+
#ifdef GCC_GE_8
53+
typedef struct dtype_type
54+
{
55+
size_t elem_len;
56+
int version;
57+
signed char rank;
58+
signed char type;
59+
signed short attribute;
60+
}
61+
dtype_type;
62+
#endif
63+
5064
typedef struct gfc_descriptor_t {
5165
void *base_addr;
5266
size_t offset;
53-
ptrdiff_t dtype;
5467
#ifdef GCC_GE_8
68+
dtype_type dtype;
5569
ptrdiff_t span;
70+
#else
71+
ptrdiff_t dtype;
5672
#endif
5773
descriptor_dimension dim[];
5874
} gfc_descriptor_t;
5975

76+
#ifdef GCC_GE_8
6077

61-
#define GFC_MAX_DIMENSIONS 7
78+
#define GFC_MAX_DIMENSIONS 15
79+
#define GFC_DTYPE_RANK_MASK 0x0F
80+
#define GFC_DTYPE_TYPE_SHIFT 4
81+
#define GFC_DTYPE_TYPE_MASK 0x70
82+
#define GFC_DTYPE_SIZE_SHIFT 7
83+
84+
#define GFC_DESCRIPTOR_RANK(desc) (desc)->dtype.rank
85+
#define GFC_DESCRIPTOR_TYPE(desc) (desc)->dtype.type
86+
#define GFC_DESCRIPTOR_SIZE(desc) (desc)->dtype.elem_len
87+
#define GFC_DTYPE_TYPE_SIZE(desc) (( ((desc)->dtype.type << GFC_DTYPE_TYPE_SHIFT) \
88+
| ((desc)->dtype.elem_len << GFC_DTYPE_SIZE_SHIFT) ) & GFC_DTYPE_TYPE_SIZE_MASK)
6289

90+
#else
91+
92+
#define GFC_MAX_DIMENSIONS 7
6393
#define GFC_DTYPE_RANK_MASK 0x07
6494
#define GFC_DTYPE_TYPE_SHIFT 3
6595
#define GFC_DTYPE_TYPE_MASK 0x38
6696
#define GFC_DTYPE_SIZE_SHIFT 6
97+
6798
#define GFC_DESCRIPTOR_RANK(desc) ((desc)->dtype & GFC_DTYPE_RANK_MASK)
6899
#define GFC_DESCRIPTOR_TYPE(desc) (((desc)->dtype & GFC_DTYPE_TYPE_MASK) \
69100
>> GFC_DTYPE_TYPE_SHIFT)
70101
#define GFC_DESCRIPTOR_SIZE(desc) ((desc)->dtype >> GFC_DTYPE_SIZE_SHIFT)
102+
#define GFC_DTYPE_TYPE_SIZE(desc) ((desc)->dtype & GFC_DTYPE_TYPE_SIZE_MASK)
103+
104+
#endif
71105

72106
#define GFC_DTYPE_SIZE_MASK \
73107
((~((ptrdiff_t) 0) >> GFC_DTYPE_SIZE_SHIFT) << GFC_DTYPE_SIZE_SHIFT)
74108
#define GFC_DTYPE_TYPE_SIZE_MASK (GFC_DTYPE_SIZE_MASK | GFC_DTYPE_TYPE_MASK)
75109

76-
#define GFC_DTYPE_TYPE_SIZE(desc) ((desc)->dtype & GFC_DTYPE_TYPE_SIZE_MASK)
77-
78110
#define GFC_DTYPE_INTEGER_1 ((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
79111
| (sizeof(int8_t) << GFC_DTYPE_SIZE_SHIFT))
80112
#define GFC_DTYPE_INTEGER_2 ((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
@@ -136,11 +168,14 @@ typedef struct gfc_descriptor_t {
136168
receives in the dtype component its gf_descriptor_t argument for character(kind=c_char)
137169
and logical(kind=c_bool) data:
138170
*/
139-
#define GFC_DTYPE_CHARACTER 48
140171

141-
#if 0
172+
#ifdef GCC_GE_8
173+
142174
#define GFC_DTYPE_CHARACTER ((BT_CHARACTER << GFC_DTYPE_TYPE_SHIFT) \
143175
| (sizeof(char) << GFC_DTYPE_SIZE_SHIFT))
176+
177+
#else
178+
#define GFC_DTYPE_CHARACTER 48
144179
#endif
145180

146181

src/libcaf-version-def.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#if __GNUC__ >= 8
2+
#define GCC_GE_8 1
3+
#endif
4+
5+
#if __GNUC__ >= 7
6+
#define GCC_GE_7 1
7+
#endif

src/libcaf.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
3232
#include <stddef.h> /* For size_t. */
3333
#include <stdbool.h>
3434

35+
#include "libcaf-version-def.h"
3536
#include "libcaf-gfortran-descriptor.h"
3637

3738
#include <mpi.h>
@@ -45,10 +46,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
4546
#define unlikely(x) __builtin_expect(!!(x), 0)
4647
#endif
4748

48-
#if __GNUC__ >= 7
49-
#define GCC_GE_7 1
50-
#endif
51-
5249
#ifdef PREFIX_NAME
5350
#define PREFIX3(X,Y) X ## Y
5451
#define PREFIX2(X,Y) PREFIX3(X,Y)

src/make.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ compiler=gnu
3737

3838
ifeq ($(compiler),gnu)
3939
FC=gfortran
40-
CC=gcc
40+
CC=mpicc
4141
MPFC = mpifort
4242
MPICC = mpicc
4343
OSHCC = oshcc
4444
FFLAGS_EXTRA = -fcoarray=lib
45-
MPI_EXTRA_FLAGS = -Wall -Wextra -Wno-error=cpp -Wno-error=unused-parameter -DSTRIDED#-DNONBLOCKING_PUT -DCAF_MPI_LOCK_UNLOCK
45+
MPI_EXTRA_FLAGS = -Wall -Wextra -Wno-error=cpp -Wno-error=unused-parameter -DSTRIDED -DUSE_FAILED_IMAGES #-DNONBLOCKING_PUT -DCAF_MPI_LOCK_UNLOCK
4646
MPI_RUN = mpiexec -np 2
4747
else
4848
ifeq ($(compiler),cray)

src/mpi/mpi_caf.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,10 @@ PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
11511151
MPI_Alloc_mem(actual_size, MPI_INFO_NULL, &mem);
11521152
MPI_Win_create(mem, actual_size, 1, MPI_INFO_NULL, CAF_COMM_WORLD, p);
11531153
#endif // MPI_VERSION
1154+
1155+
#ifndef GCC_GE_8
11541156
if (GFC_DESCRIPTOR_RANK (desc) != 0)
1157+
#endif
11551158
mpi_token->desc = desc;
11561159

11571160
if(l_var)
@@ -6092,8 +6095,13 @@ PREFIX (sendget_by_ref) (caf_token_t dst_token, int dst_image_index,
60926095
*/
60936096

60946097
dst_rank = size > 1 ? 1 : 0;
6098+
#ifdef GCC_GE_8
6099+
temp_src_desc.base.dtype.elem_len = GFC_DTYPE_INTEGER_4;
6100+
temp_src_desc.base.dtype.rank = dst_rank;
6101+
#else
60956102
temp_src_desc.base.dtype = GFC_DTYPE_INTEGER_4 |
6096-
dst_rank;
6103+
dst_rank;
6104+
#endif
60976105
temp_src_desc.base.offset = 0;
60986106
temp_src_desc.dim[0].lower_bound = 0;
60996107
temp_src_desc.dim[0]._ubound = size - 1;
@@ -7560,8 +7568,14 @@ PREFIX (failed_images) (gfc_descriptor_t *array, int team __attribute__ ((unused
75607568
array->dim[0]._ubound = -1;
75617569
array->base_addr = NULL;
75627570
#endif
7571+
7572+
#ifdef GCC_GE_8
7573+
array->dtype.type = BT_INTEGER;
7574+
array->dtype.elem_len = local_kind;
7575+
#else
75637576
array->dtype = ((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT)
75647577
| (local_kind << GFC_DTYPE_SIZE_SHIFT));
7578+
#endif
75657579
array->dim[0].lower_bound = 0;
75667580
array->dim[0]._stride = 1;
75677581
array->offset = 0;
@@ -7611,8 +7625,14 @@ PREFIX (stopped_images) (gfc_descriptor_t *array, int team __attribute__ ((unuse
76117625
array->dim[0]._ubound = -1;
76127626
array->base_addr = NULL;
76137627
#endif
7628+
7629+
#ifdef GCC_GE_8
7630+
array->dtype.type = BT_INTEGER;
7631+
array->dtype.elem_len = local_kind;
7632+
#else
76147633
array->dtype = ((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT)
76157634
| (local_kind << GFC_DTYPE_SIZE_SHIFT));
7635+
#endif
76167636
array->dim[0].lower_bound = 0;
76177637
array->dim[0]._stride = 1;
76187638
array->offset = 0;

src/tests/integration/pde_solvers/coarrayHeatSimplified/Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ compiler=gnu
33
executable=co_heat
44

55
ifeq ($(compiler),gnu)
6-
opencoarrays_dir=/opt/opencoarrays
7-
opt=-L $(opencoarrays_dir)/lib
8-
compile=mpifort -fcoarray=lib
9-
lib=-lcaf_mpi
6+
compile=caf
107
else
118
ifeq ($(compiler),intel)
129
compile=ifort -coarray=shared -standard-semantics -O3 -coarray-num-images=2

0 commit comments

Comments
 (0)