Skip to content

Commit d510348

Browse files
vehrezbeekman
authored andcommitted
Change interfaces for gcc-trunk and testcases
libcaf.h/mpi_caf.c: ------------------- Changed the library API to needs of gcc-7 by adding the new constants for caf_register and caf_deregister. Changing the interface of caf_deregster to take the dereg mode and adding the prototype for caf_is_present(). The inquiry function caf_is_present() is available as protoype only and error stops as unimplemented when called. tests/unit/init_register/*rename_me*: ------------------------------------- Renaming to reasonable filename done. tests/unit/init_register/register_alloc_comp_[1-3].f90: ------------------------------------------------------- Testing that allocation of (scalar|vector|matrix) components works. src/tests/unit/init_register/check_remote_alloced_comp_1.f90: ------------------------------------------------------------- Testing that asynchronous allocation of scalar components works. The test fails/hangs for two reasons at the moment: 1. caf_register is not asynchronously allocation components, 2. caf_is_present is not implemented and is therefore deactivated in the testsection of the main CMakeLists.txt CMakeLists.txt: --------------- Added testcases. (cherry picked from commit e3dba75 and commit ca76a39, and then these two were squashed. All code done by Andre/@vehre and original commit messages tidied by @zbeekman)
1 parent 8e7fd62 commit d510348

10 files changed

+346
-17
lines changed

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,14 @@ if(opencoarrays_aware_compiler)
360360
# Unit tests targeting each libcaf_mpi function, argument, and branch of code
361361
add_mpi_test(initialize_mpi 2 ${tests_root}/unit/init_register/initialize_mpi)
362362
add_mpi_test(register 2 ${tests_root}/unit/init_register/register)
363-
add_mpi_test(register_rename_me 2 ${tests_root}/unit/init_register/register_rename_me)
364-
add_mpi_test(register_rename_me_too 2 ${tests_root}/unit/init_register/register_rename_me_too)
363+
add_mpi_test(register_vector 2 ${tests_root}/unit/init_register/register_vector)
364+
add_mpi_test(register_alloc_vector 2 ${tests_root}/unit/init_register/register_alloc_vector)
365+
add_mpi_test(register_alloc_comp_1 2 ${tests_root}/unit/init_register/register_alloc_comp_1)
366+
add_mpi_test(register_alloc_comp_2 2 ${tests_root}/unit/init_register/register_alloc_comp_2)
367+
add_mpi_test(register_alloc_comp_3 2 ${tests_root}/unit/init_register/register_alloc_comp_3)
365368
add_mpi_test(allocate_as_barrier 2 ${tests_root}/unit/init_register/allocate_as_barrier)
366369
add_mpi_test(allocate_as_barrier_proc 32 ${tests_root}/unit/init_register/allocate_as_barrier_proc)
370+
# add_mpi_test(check_remote_alloced_comp_1 6 ${tests_root}/unit/init_register/check_remote_alloced_comp_1)
367371
add_mpi_test(get_array 2 ${tests_root}/unit/send-get/get_array)
368372
add_mpi_test(get_self 2 ${tests_root}/unit/send-get/get_self)
369373
add_mpi_test(send_array 2 ${tests_root}/unit/send-get/send_array)

src/libcaf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,10 @@ void PREFIX(sendget_by_ref) (caf_token_t dst_token, int dst_image_index,
242242
caf_reference_t *dst_refs, caf_token_t src_token, int src_image_index,
243243
caf_reference_t *src_refs, int dst_kind, int src_kind,
244244
bool may_require_tmp, int *dst_stat, int *src_stat);
245+
int PREFIX(is_present) (caf_token_t, int, caf_reference_t *refs);
245246
#endif
246247

247-
void PREFIX (co_broadcast) (gfc_descriptor_t *, int, int *, char *, int);
248+
void PREFIX (co_broadcast) (gfc_descriptor_t *, int, int *, char *, int);
248249
void PREFIX (co_max) (gfc_descriptor_t *, int, int *, char *, int, int);
249250
void PREFIX (co_min) (gfc_descriptor_t *, int, int *, char *, int, int);
250251
void PREFIX (co_reduce) (gfc_descriptor_t *, void *(*opr) (void *, void *),

src/mpi/mpi_caf.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,11 @@ PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
535535

536536
mpi_caf_token_t *mpi_token;
537537
MPI_Win *p;
538-
if (!(type == CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY
539-
|| (type == CAF_REGTYPE_COARRAY_ALLOC && *token != NULL)))
538+
if (type != CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY)
540539
*token = malloc (sizeof (mpi_caf_token_t));
541540

542541
mpi_token = (mpi_caf_token_t *) *token;
543542
p = TOKEN(mpi_token);
544-
fprintf (stderr, "%d: _caf_register(type = %d, token = %p)!\n", caf_this_image, type, *token);
545543

546544
if (type == CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY
547545
|| type == CAF_REGTYPE_COARRAY_ALLOC
@@ -564,8 +562,6 @@ PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
564562
#if MPI_VERSION >= 3
565563
if (type != CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY)
566564
{
567-
fprintf (stderr, "%d: Adding memory to token %p, desc = %p.\n",
568-
caf_this_image, token, mpi_token->desc);
569565
MPI_Win_allocate (actual_size, 1, MPI_INFO_NULL, CAF_COMM_WORLD, &mem, p);
570566
CAF_Win_lock_all (*p);
571567
}
@@ -588,7 +584,7 @@ PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
588584

589585
if (type != CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY)
590586
{
591-
PREFIX(sync_all) (NULL,NULL,0);
587+
// PREFIX(sync_all) (NULL,NULL,0);
592588

593589
caf_static_t *tmp = malloc (sizeof (caf_static_t));
594590
tmp->prev = caf_tot;
@@ -641,11 +637,11 @@ PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
641637
#ifdef COMPILER_SUPPORTS_CAF_INTRINSICS
642638
void *
643639
_gfortran_caf_register (size_t size, caf_register_t type, caf_token_t *token,
644-
int *stat, char *errmsg, int errmsg_len)
640+
int *stat, char *errmsg, int errmsg_len)
645641
#else
646642
void *
647643
PREFIX (register) (size_t size, caf_register_t type, caf_token_t *token,
648-
int *stat, char *errmsg, int errmsg_len)
644+
int *stat, char *errmsg, int errmsg_len)
649645
#endif
650646
{
651647
/* int ierr; */
@@ -764,8 +760,6 @@ PREFIX (deregister) (caf_token_t *token, int *stat, char *errmsg, int errmsg_len
764760
{
765761
/* int ierr; */
766762

767-
fprintf (stderr, "%d: deregistering token = %p, type = %d.\n", caf_this_image,
768-
*token, type);
769763
if (unlikely (caf_is_finalized))
770764
{
771765
const char msg[] = "Failed to deallocate coarray - "
@@ -2979,6 +2973,14 @@ PREFIX(sendget_by_ref) (caf_token_t dst_token, int dst_image_index,
29792973
fprintf (stderr, "COARRAY ERROR: caf_sendget_by_ref() not implemented yet ");
29802974
error_stop (1);
29812975
}
2976+
2977+
2978+
int
2979+
PREFIX(is_present) (caf_token_t token, int image_index, caf_reference_t *refs)
2980+
{
2981+
fprintf (stderr, "COARRAY ERROR: caf_is_present() not implemented yet ");
2982+
error_stop (1);
2983+
}
29822984
#endif
29832985

29842986

src/tests/unit/init_register/CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,26 @@ target_link_libraries(initialize_mpi OpenCoarrays)
44
add_executable(register register.f90)
55
target_link_libraries(register OpenCoarrays)
66

7-
add_executable(register_rename_me register_rename_me.f90)
8-
target_link_libraries(register_rename_me OpenCoarrays)
7+
add_executable(register_vector register_vector.f90)
8+
target_link_libraries(register_vector OpenCoarrays)
99

10-
add_executable(register_rename_me_too register_rename_me_too.f90)
11-
target_link_libraries(register_rename_me_too OpenCoarrays)
10+
add_executable(register_alloc_vector register_alloc_vector.f90)
11+
target_link_libraries(register_alloc_vector OpenCoarrays)
12+
13+
add_executable(register_alloc_comp_1 register_alloc_comp_1.f90)
14+
target_link_libraries(register_alloc_comp_1 OpenCoarrays)
15+
16+
add_executable(register_alloc_comp_2 register_alloc_comp_2.f90)
17+
target_link_libraries(register_alloc_comp_2 OpenCoarrays)
18+
19+
add_executable(register_alloc_comp_3 register_alloc_comp_3.f90)
20+
target_link_libraries(register_alloc_comp_3 OpenCoarrays)
1221

1322
add_executable(allocate_as_barrier allocate_as_barrier.f90)
1423
target_link_libraries(allocate_as_barrier OpenCoarrays)
1524

1625
add_executable(allocate_as_barrier_proc allocate_as_barrier_proc.f90)
1726
target_link_libraries(allocate_as_barrier_proc OpenCoarrays)
27+
28+
add_executable(check_remote_alloced_comp_1 check_remote_alloced_comp_1.f90)
29+
target_link_libraries(check_remote_alloced_comp_1 OpenCoarrays)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
! Unit test for register procedure and remote allocated test.
2+
!
3+
! Test that scalar allocatable component in a derived typed coarray is
4+
! registered correctly, delayed allocatable and deregisterable. The checks
5+
! whether the component is allocated are done on the remote images.
6+
!
7+
! Copyright (c) 2012-2016, Sourcery, Inc.
8+
! All rights reserved.
9+
!
10+
! Redistribution and use in source and binary forms, with or without
11+
! modification, are permitted provided that the following conditions are met:
12+
! * Redistributions of source code must retain the above copyright
13+
! notice, this list of conditions and the following disclaimer.
14+
! * Redistributions in binary form must reproduce the above copyright
15+
! notice, this list of conditions and the following disclaimer in the
16+
! documentation and/or other materials provided with the distribution.
17+
! * Neither the name of the Sourcery, Inc., nor the
18+
! names of its contributors may be used to endorse or promote products
19+
! derived from this software without specific prior written permission.
20+
!
21+
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
! ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
! WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
! DISCLAIMED. IN NO EVENT SHALL SOURCERY, INC., BE LIABLE FOR ANY
25+
! DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
! (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28+
! ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
program check_remote_alloced_comp_1
33+
implicit none
34+
35+
type dt
36+
integer, allocatable :: i
37+
end type dt
38+
39+
integer :: np = -2, me, remote, test
40+
type(dt), allocatable :: obj[:]
41+
42+
np = num_images()
43+
me = this_image()
44+
45+
! Make sure that at least two images are available. This might not be
46+
! necessary, but simplyfies writing the test.
47+
if (np < 2) error stop "Test failed. Need more than one image."
48+
49+
! Allocate only the container. obj%i must not be allocated hereafter.
50+
allocate(obj[*])
51+
if (.not. allocated(obj)) error stop "Test failed. 'obj' not allocated."
52+
if (allocated(obj%i)) error stop "Test failed. 'obj%i' is allocated."
53+
54+
! The print statements are in for debugging purposes only.
55+
56+
! All images have allocated the container. Now iterate over the images and
57+
! when this image's number is equal to remote, allocate the component,
58+
! else check the allocation status of all other remote components.
59+
do remote = 1, np
60+
print *, me, "/", np, ": remote=", remote
61+
if (remote == me) then
62+
print *, me, "/", np, ": allocating..."
63+
allocate(obj%i, source = me)
64+
print *, me, "/", np, ": allocated"
65+
! Now both objects have to be allocated and obj%i set to this_image()
66+
if (.not. allocated(obj)) error stop "Test failed. 'obj' not allocated."
67+
if (.not. allocated(obj%i)) error stop "Test failed. 'obj%i' not allocated."
68+
if (obj%i /= me) error stop "Test failed. obj%i /= this_image()."
69+
sync all
70+
else
71+
sync all
72+
! Iterate using test over the images to test:
73+
! when test less or equal than remote, check that the remote image's
74+
! component given by test is allocated,
75+
! else check that the remote component is not yet allocated.
76+
do test = 1, np
77+
print *, me, "/", np, ": Checking", test, " for allocation status."
78+
if (test > remote) then
79+
if (allocated(obj[test]%i)) error stop "Test failed. 'obj%i' on remote image already allocated."
80+
else
81+
if (.not. allocated(obj[test]%i)) error stop "Test failed. 'obj%i' on remote image not allocated."
82+
end if
83+
end do
84+
end if
85+
enddo
86+
end program
87+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
! Unit test for register and allocated procedure.
2+
!
3+
! Test that scalar allocatable component in a derived typed coarray is
4+
! registered correctly, delayed allocatable and deregisterable. The checks
5+
! whether a component is allocated are done on this_image only.
6+
!
7+
! Copyright (c) 2012-2016, Sourcery, Inc.
8+
! All rights reserved.
9+
!
10+
! Redistribution and use in source and binary forms, with or without
11+
! modification, are permitted provided that the following conditions are met:
12+
! * Redistributions of source code must retain the above copyright
13+
! notice, this list of conditions and the following disclaimer.
14+
! * Redistributions in binary form must reproduce the above copyright
15+
! notice, this list of conditions and the following disclaimer in the
16+
! documentation and/or other materials provided with the distribution.
17+
! * Neither the name of the Sourcery, Inc., nor the
18+
! names of its contributors may be used to endorse or promote products
19+
! derived from this software without specific prior written permission.
20+
!
21+
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
! ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
! WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
! DISCLAIMED. IN NO EVENT SHALL SOURCERY, INC., BE LIABLE FOR ANY
25+
! DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
! (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28+
! ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
program register_alloc_comp_1
33+
implicit none
34+
35+
type dt
36+
integer, allocatable :: i
37+
end type dt
38+
39+
integer :: np = -2
40+
type(dt), allocatable :: obj[:]
41+
42+
np = num_images()
43+
44+
! Allocate only the container. obj%i must not be allocated hereafter.
45+
allocate(obj[*])
46+
if (.not. allocated(obj)) error stop "Test failed. 'obj' not allocated."
47+
if (allocated(obj%i)) error stop "Test failed. 'obj%i' is allocated."
48+
49+
! Allocate the component.
50+
allocate(obj%i, source=this_image())
51+
52+
! Now both objects have to be allocated and obj%i set to this_image()
53+
if (.not. allocated(obj)) error stop "Test failed. 'obj' not allocated."
54+
if (.not. allocated(obj%i)) error stop "Test failed. 'obj%i' not allocated."
55+
if (obj%i /= this_image()) error stop "Test failed. obj%i /= this_image()."
56+
57+
! Deallocate the component.
58+
deallocate(obj%i)
59+
60+
! and test, that only the component is deallocated, but not the container.
61+
if (allocated(obj%i)) error stop "Test failed. 'obj%i' still allocated."
62+
if (.not. allocated(obj)) error stop "Test failed. 'obj' no longer allocated."
63+
64+
! Now deallocate the container, too.
65+
deallocate(obj)
66+
67+
! and check, that it worked.
68+
if (allocated(obj)) error stop "Test failed. 'obj' still allocated."
69+
70+
! Failing tests would make whole program error out. Therefore it is save
71+
! to print the pass message on image one, only.
72+
if (this_image() == 1) print *, "Test passed."
73+
end program
74+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
! Unit test for register and allocated procedure.
2+
!
3+
! Test that vector valued allocatable components in a derived typed coarray is
4+
! registered correctly, delayed allocatable and deregisterable. The checks
5+
! whether a component is allocated are done on this_image only.
6+
!
7+
! Copyright (c) 2012-2016, Sourcery, Inc.
8+
! All rights reserved.
9+
!
10+
! Redistribution and use in source and binary forms, with or without
11+
! modification, are permitted provided that the following conditions are met:
12+
! * Redistributions of source code must retain the above copyright
13+
! notice, this list of conditions and the following disclaimer.
14+
! * Redistributions in binary form must reproduce the above copyright
15+
! notice, this list of conditions and the following disclaimer in the
16+
! documentation and/or other materials provided with the distribution.
17+
! * Neither the name of the Sourcery, Inc., nor the
18+
! names of its contributors may be used to endorse or promote products
19+
! derived from this software without specific prior written permission.
20+
!
21+
! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22+
! ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
! WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
! DISCLAIMED. IN NO EVENT SHALL SOURCERY, INC., BE LIABLE FOR ANY
25+
! DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
! (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28+
! ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
program register_alloc_comp_2
33+
implicit none
34+
35+
type dt
36+
integer, allocatable, dimension(:) :: v
37+
end type dt
38+
39+
integer :: np = -2
40+
type(dt), allocatable :: obj[:]
41+
42+
np = num_images()
43+
44+
! Allocate only the container. obj%v must not be allocated hereafter.
45+
allocate(obj[*])
46+
if (.not. allocated(obj)) error stop "Test failed. 'obj' not allocated."
47+
if (allocated(obj%v)) error stop "Test failed. 'obj%v' is allocated."
48+
49+
! Allocate the component and initialize it with this_image()
50+
allocate(obj%v(5), source=this_image())
51+
52+
! Now both objects have to be allocated and obj%v(1:5) set to this_image()
53+
if (.not. allocated(obj)) error stop "Test failed. 'obj' not allocated."
54+
if (.not. allocated(obj%v)) error stop "Test failed. 'obj%v' not allocated."
55+
if (any (obj%v(:) /= this_image())) error stop "Test failed. obj%v(:) /= this_image()."
56+
57+
! Deallocate the component.
58+
deallocate(obj%v)
59+
60+
! and test, that only the component is deallocated, but not the container.
61+
if (allocated(obj%v)) error stop "Test failed. 'obj%v' still allocated."
62+
if (.not. allocated(obj)) error stop "Test failed. 'obj' no longer allocated."
63+
64+
! Now deallocate the container, too.
65+
deallocate(obj)
66+
67+
! and check, that it worked.
68+
if (allocated(obj)) error stop "Test failed. 'obj' still allocated."
69+
70+
! Failing tests would make whole program error out. Therefore it is save
71+
! to print the pass message on image one, only.
72+
if (this_image() == 1) print *, "Test passed."
73+
end program
74+

0 commit comments

Comments
 (0)