From ffaf9305aa0f0d4a4cc6cc8afa5444b94b2b67a0 Mon Sep 17 00:00:00 2001 From: Andre Vehreschild Date: Fri, 9 Dec 2016 13:46:57 +0100 Subject: [PATCH] re PR fortran/78505 ([F08] Coarray source allocation not synchronizing on oversubscribed cores) gcc/fortran/ChangeLog: 2016-12-09 Andre Vehreschild PR fortran/78505 * trans-stmt.c (gfc_trans_allocate): Add sync all after the execution of the whole allocate-statement to adhere to the standard. gcc/testsuite/ChangeLog: 2016-12-09 Andre Vehreschild PR fortran/78505 * gfortran.dg/coarray_alloc_with_implicit_sync_1.f90: New test. From-SVN: r243482 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/trans-stmt.c | 25 +++++++++++++++++++--- gcc/testsuite/ChangeLog | 5 +++++ .../coarray_alloc_with_implicit_sync_1.f90 | 10 +++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/coarray_alloc_with_implicit_sync_1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index fe68bf4..2342163 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,5 +1,11 @@ 2016-12-09 Andre Vehreschild + PR fortran/78505 + * trans-stmt.c (gfc_trans_allocate): Add sync all after the execution + of the whole allocate-statement to adhere to the standard. + +2016-12-09 Andre Vehreschild + * trans-array.c (gfc_array_deallocate): Remove wrapper. (gfc_trans_dealloc_allocated): Same. (structure_alloc_comps): Restructure deallocation of (nested) diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 5ca716b..d34bdba 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -5506,7 +5506,7 @@ gfc_trans_allocate (gfc_code * code) stmtblock_t block; stmtblock_t post; tree nelems; - bool upoly_expr, tmp_expr3_len_flag = false, al_len_needs_set; + bool upoly_expr, tmp_expr3_len_flag = false, al_len_needs_set, is_coarray ; gfc_symtree *newsym = NULL; if (!code->ext.alloc.list) @@ -5516,6 +5516,7 @@ gfc_trans_allocate (gfc_code * code) expr3 = expr3_vptr = expr3_len = expr3_esize = NULL_TREE; label_errmsg = label_finish = errmsg = errlen = NULL_TREE; e3_is = E3_UNSET; + is_coarray = false; gfc_init_block (&block); gfc_init_block (&post); @@ -5555,8 +5556,9 @@ gfc_trans_allocate (gfc_code * code) expression. */ if (code->expr3) { - bool vtab_needed = false, temp_var_needed = false, - is_coarray = gfc_is_coarray (code->expr3); + bool vtab_needed = false, temp_var_needed = false; + + is_coarray = gfc_is_coarray (code->expr3); /* Figure whether we need the vtab from expr3. */ for (al = code->ext.alloc.list; !vtab_needed && al != NULL; @@ -6093,6 +6095,9 @@ gfc_trans_allocate (gfc_code * code) tree caf_decl, token; gfc_se caf_se; + /* Set flag, to add synchronize after the allocate. */ + is_coarray = true; + gfc_init_se (&caf_se, NULL); caf_decl = gfc_get_tree_for_caf_expr (expr); @@ -6114,6 +6119,11 @@ gfc_trans_allocate (gfc_code * code) } else { + /* Allocating coarrays needs a sync after the allocate executed. + Set the flag to add the sync after all objects are allocated. */ + is_coarray = is_coarray || (gfc_caf_attr (expr).codimension + && flag_coarray == GFC_FCOARRAY_LIB); + if (expr->ts.type == BT_CHARACTER && al_len != NULL_TREE && expr3_len != NULL_TREE) { @@ -6357,6 +6367,15 @@ gfc_trans_allocate (gfc_code * code) gfc_add_modify (&block, se.expr, tmp); } + if (is_coarray && flag_coarray == GFC_FCOARRAY_LIB) + { + /* Add a sync all after the allocation has been executed. */ + tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_sync_all, + 3, null_pointer_node, null_pointer_node, + integer_zero_node); + gfc_add_expr_to_block (&post, tmp); + } + gfc_add_block_to_block (&block, &se.post); gfc_add_block_to_block (&block, &post); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 33e5b37..49146a3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2016-12-09 Andre Vehreschild + PR fortran/78505 + * gfortran.dg/coarray_alloc_with_implicit_sync_1.f90: New test. + +2016-12-09 Andre Vehreschild + * gfortran.dg/coarray_alloc_comp_3.f08: New test. * gfortran.dg/coarray_alloc_comp_4.f08: New test. * gfortran.dg/finalize_18.f90: Add count for additional guard against diff --git a/gcc/testsuite/gfortran.dg/coarray_alloc_with_implicit_sync_1.f90 b/gcc/testsuite/gfortran.dg/coarray_alloc_with_implicit_sync_1.f90 new file mode 100644 index 0000000..1dbbcb7 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray_alloc_with_implicit_sync_1.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! { dg-options "-fdump-tree-original -fcoarray=lib" } +! Check that allocating a coarray adds an implicit sync all. + + implicit none + integer, allocatable :: f(:)[:] + allocate( f(20)[*], source = 1 ) +end + +! { dg-final { scan-tree-dump-times "_gfortran_caf_sync_all \\(" 1 "original" } } -- 2.7.4