Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ if(opencoarrays_aware_compiler)
add_mpi_test(whole_get_array 2 ${tests_root}/unit/send-get/whole_get_array)
add_mpi_test(strided_get 2 ${tests_root}/unit/send-get/strided_get)
add_mpi_test(collectives 2 ${tests_root}/unit/collectives/collectives)

add_mpi_test(syncall 4 ${tests_root}/unit/sync/syncall)
add_mpi_test(syncimages 4 ${tests_root}/unit/sync/syncimages)
add_mpi_test(syncimages_status 4 ${tests_root}/unit/sync/syncimages_status)

# Integration tests verifying the use of libcaf_mpi in applications
add_mpi_test(hello_multiverse 2 ${tests_root}/integration/coarrayHelloWorld/hello_multiverse)
add_mpi_test(coarray_burgers_pde 2 ${tests_root}/integration/pde_solvers/coarrayBurgers/coarray_burgers_pde)
Expand Down
49 changes: 45 additions & 4 deletions src/mpi/mpi_caf.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ static win_sync *pending_puts = NULL;
caf_static_t *caf_static_list = NULL;
caf_static_t *caf_tot = NULL;

/* Image status variable */

static int *img_status = NULL;
MPI_Win *stat_tok;

/* Active messages variables */

char **buff_am;
Expand Down Expand Up @@ -185,7 +190,7 @@ caf_runtime_error (const char *message, ...)

/* FIXME: Shutdown the Fortran RTL to flush the buffer. PR 43849. */
/* FIXME: Do some more effort than just to abort. */
MPI_Finalize();
// MPI_Finalize();

/* Should be unreachable, but to make sure also call exit. */
exit (EXIT_FAILURE);
Expand Down Expand Up @@ -367,11 +372,23 @@ PREFIX (init) (int *argc, char ***argv)

handlers = malloc(caf_num_images * sizeof(MPI_Request));

stat_tok = malloc (sizeof(MPI_Win));

#if MPI_VERSION >= 3
MPI_Info_create (&mpi_info_same_size);
MPI_Info_set (mpi_info_same_size, "same_size", "true");
/* Setting img_status */
MPI_Win_allocate(sizeof(int), 1, mpi_info_same_size, CAF_COMM_WORLD, &img_status, stat_tok);
# ifndef CAF_MPI_LOCK_UNLOCK
MPI_Win_lock_all(MPI_MODE_NOCHECK, *stat_tok);
# endif // CAF_MPI_LOCK_UNLOCK
#else
MPI_Alloc_mem(sizeof(int), MPI_INFO_NULL, &img_status, stat_tok);
MPI_Win_create(img_status, sizeof(int), 1, MPI_INFO_NULL, CAF_COMM_WORLD, stat_tok);
#endif // MPI_VERSION
*img_status = 0;
}
/* MPI_Barrier(CAF_COMM_WORLD); */
}


Expand All @@ -384,7 +401,8 @@ _gfortran_caf_finalize (void)
PREFIX (finalize) (void)
#endif
{

*img_status = STAT_STOPPED_IMAGE; /* GFC_STAT_STOPPED_IMAGE = 6000 */
MPI_Win_sync(*stat_tok);
MPI_Barrier(CAF_COMM_WORLD);

while (caf_static_list != NULL)
Expand Down Expand Up @@ -1567,10 +1585,31 @@ void
PREFIX (sync_images) (int count, int images[], int *stat, char *errmsg,
int errmsg_len)
{
int ierr = 0, i=0;
int ierr = 0, i=0, remote_stat = 0;

MPI_Status s;

for(i=0;i<caf_num_images-1;i++)
{
# ifdef CAF_MPI_LOCK_UNLOCK
MPI_Win_lock (MPI_LOCK_SHARED, i, 0, *stat_tok);
# endif // CAF_MPI_LOCK_UNLOCK
ierr = MPI_Get (&remote_stat, 1, MPI_INT,
i, 0, 1, MPI_INT, *stat_tok);
# ifdef CAF_MPI_LOCK_UNLOCK
MPI_Win_unlock (i, *stat_tok);
# else // CAF_MPI_LOCK_UNLOCK
MPI_Win_flush (i, *stat_tok);
# endif // CAF_MPI_LOCK_UNLOCK
if(remote_stat != 0)
{
ierr = STAT_STOPPED_IMAGE;
if(stat != NULL)
*stat = ierr;
goto sync_images_err_chk;
}
}

if (count == 0 || (count == 1 && images[0] == caf_this_image))
{
if (stat)
Expand Down Expand Up @@ -1627,7 +1666,9 @@ PREFIX (sync_images) (int count, int images[], int *stat, char *errmsg,
if (stat)
*stat = ierr;

if (ierr)
sync_images_err_chk:

if (ierr && stat == NULL)
{
char *msg;
if (caf_is_finalized)
Expand Down
1 change: 1 addition & 0 deletions src/tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ if (${opencoarrays_aware_compiler})
add_subdirectory(send-get)
add_subdirectory(init_register)
add_subdirectory(collectives)
add_subdirectory(sync)
add_subdirectory(extensions)
endif()
2 changes: 1 addition & 1 deletion src/tests/unit/extensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set(source collectives_extensions.F90)
# running the test. We therefore copy the uncompiled source to the
# build tree:
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/../collectives/collectives_tests.f90
${CMAKE_CURRENT_SOURCE_DIR}/../collectives/collectives_tests.F90
${CMAKE_CURRENT_BINARY_DIR}/${source}
COPYONLY
)
Expand Down
20 changes: 20 additions & 0 deletions src/tests/unit/sync/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
add_executable(syncall syncall.f90)
target_link_libraries(syncall OpenCoarrays)

add_executable(syncimages syncimages.f90)
target_link_libraries(syncimages OpenCoarrays)

add_executable(syncimages_status syncimages_status.f90)
target_link_libraries(syncimages_status OpenCoarrays)

#add_executable(send_array send_array_test.f90)
#target_link_libraries(send_array OpenCoarrays)

#add_executable(get_with_offset_1d get_with_offset_1d.f90)
#target_link_libraries(get_with_offset_1d OpenCoarrays)

#add_executable(whole_get_array whole_get_array.f90)
#target_link_libraries(whole_get_array OpenCoarrays)

#add_executable(strided_get strided_get.f90)
#target_link_libraries(strided_get OpenCoarrays)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
! ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
!
program syncall1
program syncall
implicit none

integer :: me,np,i
Expand All @@ -51,4 +51,4 @@ program syncall1

if(me == 1) print *,'Test passed.'

end program syncall1
end program syncall
23 changes: 23 additions & 0 deletions src/tests/unit/sync/syncimages_status.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
! SYNC IMAGES(*) with the STAT=STAT_STOPPED_IMAGE specifier
! Based on a test taken from UH caf-testsuite

program sync_images_stat
use, intrinsic:: iso_fortran_env
implicit none

integer :: stat_var = 0, me

me = this_image()

if (me /= 1 ) then
call sleep(1)
sync images(*,STAT=stat_var)
if ( stat_var /= STAT_STOPPED_IMAGE) then
print *, "Error:stat_var /= STAT_STOPPED_IMAGE: ", me
ERROR STOP 1
end if
if(me == 2) print *, 'Test passed.'
end if

end program sync_images_stat