Skip to content

Commit

Permalink
Merge pull request #21 from BerkeleyLab/flang-issue-109589
Browse files Browse the repository at this point in the history
Use language-feature macros and work around flang I/O issue
  • Loading branch information
rouson authored Sep 22, 2024
2 parents 1ab6b65 + 3a02b5d commit 1eb98b8
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 49 deletions.
33 changes: 33 additions & 0 deletions include/language-support.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
! Copyright (c), The Regents of the University of California
! Terms of use are as specified in LICENSE.txt

#ifndef HAVE_SELECTED_LOGICAL_KIND
! Define whether the compiler supports standard intrinsic function selected_logical_kind(),
! a feature introduced in Fortran 2023 clause 16.9.182.
#if defined(_CRAYFTN) || defined(NAGFOR) || defined(__flang__)
#define HAVE_SELECTED_LOGICAL_KIND 1
#else
#define HAVE_SELECTED_LOGICAL_KIND 0
#endif
#endif

#ifndef HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
! Define whether the compiler supports associating a procedure pointer dummy argument with an
! actual argument that is a valid target for the pointer dummy in a procedure assignment, a
! feature introduced in Fortran 2008 and described in Fortran 2023 clause 15.5.2.10 paragraph 5.
#if defined(_CRAYFTN) || defined(__INTEL_COMPILER) || defined(NAGFOR) || defined(__flang__)
#define HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY 1
#else
#define HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY 0
#endif
#endif

#ifndef HAVE_MULTI_IMAGE_SUPPORT
! Define whether the compiler supports the statements and intrinsic procedures that support
! multi-image execution, e.g., this_image(), sync all, etc.
#if defined(_CRAYFTN) || defined(__INTEL_COMPILER) || defined(NAGFOR) || defined(__GFORTRAN__)
#define HAVE_MULTI_IMAGE_SUPPORT 1
#else
#define HAVE_MULTI_IMAGE_SUPPORT 0
#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
use julienne_user_defined_collectives_m, only : co_all
implicit none

#ifdef __flang__
#define NO_MULTI_IMAGE_SUPPORT
#endif

contains

module procedure construct_from_character
Expand All @@ -26,9 +22,7 @@

module procedure passed
test_passed = self%passed_
#ifndef NO_MULTI_IMAGE_SUPPORT
call co_all(test_passed)
#endif
end procedure

module procedure description_contains
Expand Down
31 changes: 14 additions & 17 deletions src/julienne/julienne_test_s.F90
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt

#include "language-support.F90"

submodule(julienne_test_m) julienne_test_s
use julienne_user_defined_collectives_m, only : co_all
use julienne_command_line_m, only : command_line_t
implicit none

#if defined(__flang__)
#define NO_MULTI_IMAGE_SUPPORT
#endif

contains

module procedure report
#ifdef NO_MULTI_IMAGE_SUPPORT
#if HAVE_MULTI_IMAGE_SUPPORT
associate(me => this_image())
#else
integer me
me = 1
#else
associate(me => this_image())
#endif


if (me==1) then

first_report: &
Expand All @@ -28,19 +26,20 @@
type(command_line_t) command_line
test_description_substring = command_line%flag_value("--contains")
end block
print *
if (len(test_description_substring)==0) then
print*,"Running all tests."
print*,"(Add '-- --contains <string>' to run only tests with subjects or descriptions containing the specified string.)"
print '(a)',"Running all tests."
print '(a)',"(Add '-- --contains <string>' to run only tests with subjects or descriptions containing the specified string.)"
else
print *,"Running only tests with subjects or descriptions containing '", test_description_substring,"'."
print '(*(a))',"Running only tests with subjects or descriptions containing '", test_description_substring,"'."
end if
end if first_report

print *, new_line('a'), test%subject()

end if

#ifndef NO_MULTI_IMAGE_SUPPORT
#if HAVE_MULTI_IMAGE_SUPPORT
call co_broadcast(test_description_substring, source_image=1)
#endif

Expand All @@ -52,23 +51,21 @@
block
integer i
do i=1,num_tests
if (me==1) print *," ",test_results(i)%characterize()
if (me==1) print '(3x,a)', test_results(i)%characterize()
end do
end block
end if
block
logical, allocatable :: passing_tests(:)
passing_tests = test_results%passed()
#ifndef NO_MULTI_IMAGE_SUPPORT
call co_all(passing_tests)
#endif
associate(num_passes => count(passing_tests))
if (me==1) print '(a,2(i0,a))'," ",num_passes," of ", num_tests," tests pass."
passes = passes + num_passes
end associate
end block
end associate
#ifndef NO_MULTI_IMAGE_SUPPORT
#if HAVE_MULTI_IMAGE_SUPPORT
end associate
#endif

Expand All @@ -83,7 +80,7 @@
tests = tests + num_tests
if (me==1) then
do i=1,num_tests
if (me==1) print *," ",test_results(i)%characterize()
if (me==1) print '(3x,a)', test_results(i)%characterize()
end do
end if
passing_tests = test_results%passed()
Expand Down
5 changes: 1 addition & 4 deletions src/julienne/julienne_user_defined_collectives_s.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
! "Multi-Dimensional Physics Implementation into Fuel Analysis under Steady-state and Transients (FAST)",
! contract # NRC-HQ-60-17-C-0007
!
#ifdef __flang__
#define NO_MULTI_IMAGE_SUPPORT
#endif
submodule(julienne_user_defined_collectives_m) julienne_user_defined_collectives_s
implicit none

contains

module procedure co_all
#ifndef NO_MULTI_IMAGE_SUPPORT
#if HAVE_MULTI_IMAGE_SUPPORT
call co_reduce(boolean, both)
#endif
contains
Expand Down
7 changes: 5 additions & 2 deletions test/bin_test.F90
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt

#include "language-support.F90"

module bin_test_m
!! Check data partitioning across bins
use julienne_m, only : bin_t, test_t, test_result_t, test_description_t, test_description_substring, string_t
#ifdef __GFORTRAN__
#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
use julienne_m, only : test_function_i
#endif
use assert_m, only : assert
Expand All @@ -29,7 +32,7 @@ function results() result(test_results)
type(test_result_t), allocatable :: test_results(:)
type(test_description_t), allocatable :: test_descriptions(:)

#ifndef __GFORTRAN__
#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
test_descriptions = [ &
test_description_t(string_t("partitioning items nearly evenly across bins"), check_block_partitioning), &
test_description_t(string_t("partitioning all item across all bins without item loss"), check_all_items_partitioned) &
Expand Down
7 changes: 5 additions & 2 deletions test/command_line_test.F90
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt

#include "language-support.F90"

module command_line_test_m
!! Verify object pattern asbtract parent
use julienne_m, only : test_t, test_result_t, command_line_t, test_description_substring, string_t, test_description_t
#ifdef __GFORTRAN__
#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
use julienne_m, only : test_function_i
#endif

Expand All @@ -28,7 +31,7 @@ pure function subject() result(specimen)
function results() result(test_results)
type(test_result_t), allocatable :: test_results(:)
type(test_description_t), allocatable :: test_descriptions(:)
#ifndef __GFORTRAN__
#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
test_descriptions = [ &
test_description_t(string_t("returning the value passed after a command-line flag"), check_flag_value), &
test_description_t(string_t("returning an empty string when a flag value is missing"), handle_missing_flag_value), &
Expand Down
7 changes: 5 additions & 2 deletions test/formats_test.F90
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt

#include "language-support.F90"

module formats_test_m
!! Verify that format strings provide the desired formatting
use julienne_m, only : separated_values, test_t, test_result_t, test_description_t, test_description_substring, string_t
#ifdef __GFORTRAN__
#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
use julienne_m, only : test_function_i
#endif

Expand All @@ -29,7 +32,7 @@ function results() result(test_results)
type(test_result_t), allocatable :: test_results(:)
type(test_description_t), allocatable :: test_descriptions(:)

#ifndef __GFORTRAN__
#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
test_descriptions = [ &
test_description_t(string_t("yielding a comma-separated list of real numbers"), check_csv_reals), &
test_description_t(string_t("yielding a comma-separated list of double-precision numbers"), check_csv_double_precision), &
Expand Down
19 changes: 12 additions & 7 deletions test/main.F90
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt

#if defined(__flang__)
#define NO_MULTI_IMAGE_SUPPORT
#endif
#include "language-support.F90"

program main
!! Julienne unit tests driver
Expand Down Expand Up @@ -51,10 +49,17 @@ program main
call vector_test_description_test%report(passes,tests)
if (.not. GitHub_CI()) call command_line_test%report(passes, tests)

#ifndef NO_MULTI_IMAGE_SUPPORT
if (this_image()==1) &
#if HAVE_MULTI_IMAGE_SUPPORT
if (this_image()==1) then
#endif

print *
print '(*(a,:,g0))', "_________ In total, ",passes," of ",tests, " tests pass. _________"

if (passes /= tests) error stop "Some tests failed."

#if HAVE_MULTI_IMAGE_SUPPORT
end if
#endif
print *, new_line('a'), "_________ In total, ",passes," of ",tests, " tests pass. _________"
if (passes /= tests) error stop

end program
7 changes: 5 additions & 2 deletions test/string_test.F90
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt

#include "language-support.F90"

module string_test_m
use julienne_m, only : test_t, test_result_t, string_t, operator(.cat.), test_description_t, test_description_substring
#ifdef __GFORTRAN__
#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
use julienne_m, only : test_function_i
#endif
implicit none
Expand All @@ -27,7 +30,7 @@ function results() result(test_results)
type(test_result_t), allocatable :: test_results(:)
type(test_description_t), allocatable :: test_descriptions(:)

#ifndef __GFORTRAN__
#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
test_descriptions = [ &
test_description_t &
(string_t("is_allocated() result .true. if & only if the string_t component(s) is/are allocated"), check_allocation), &
Expand Down
9 changes: 6 additions & 3 deletions test/test_description_test.F90
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt

#include "language-support.F90"

module test_description_test_m
!! Verify test_description_t object behavior
use julienne_m, only : string_t, test_result_t, test_description_t, test_t, test_description_substring
#ifdef __GFORTRAN__
#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
use julienne_m, only : test_function_i
#endif
implicit none
Expand All @@ -28,7 +31,7 @@ function results() result(test_results)
type(test_result_t), allocatable :: test_results(:)
type(test_description_t), allocatable :: test_descriptions(:)

#ifndef __GFORTRAN__
#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
test_descriptions = [ &
test_description_t("identical construction from string_t or character arguments", check_character_constructor) &
]
Expand All @@ -51,7 +54,7 @@ function results() result(test_results)

function check_character_constructor() result(passed)
logical passed
#ifndef __GFORTRAN__
#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
passed = test_description_t("foo", tautology) == test_description_t(string_t("foo"), tautology)
#else
procedure(test_function_i), pointer :: test_function_ptr
Expand Down
13 changes: 9 additions & 4 deletions test/test_result_test.F90
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
! Copyright (c) 2024, The Regents of the University of California and Sourcery Institute
! Terms of use are as specified in LICENSE.txt

#include "language-support.F90"

module test_result_test_m
!! Verify test_result_t object behavior
use julienne_m, only : string_t, test_result_t, test_description_t, test_t, test_description_substring
#ifdef __GFORTRAN__
#if ! HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
use julienne_m, only : test_function_i
#endif
implicit none
Expand All @@ -28,7 +31,7 @@ function results() result(test_results)
type(test_result_t), allocatable :: test_results(:)
type(test_description_t), allocatable :: test_descriptions(:)

#ifndef __GFORTRAN__
#if HAVE_PROCEDURE_ACTUAL_FOR_POINTER_DUMMY
test_descriptions = [ &
test_description_t(string_t("constructing an array of test_result_t objects elementally"), check_array_result_construction), &
test_description_t(string_t("reporting failure if the test fails on one image"), check_single_image_failure) &
Expand Down Expand Up @@ -61,11 +64,13 @@ function check_single_image_failure() result(passed)
type(test_result_t), allocatable :: test_result
logical passed

#ifndef __flang__
#if HAVE_MULTI_IMAGE_SUPPORT
if (this_image()==1) then
#endif

test_result = test_result_t("image 1 fails", .false.)
#ifndef __flang__

#if HAVE_MULTI_IMAGE_SUPPORT
else
test_result = test_result_t("all images other than 1 pass", .true.)
end if
Expand Down

0 comments on commit 1eb98b8

Please sign in to comment.