From ffdc4af209d3db4e49c0c294bca1ac29ddcb2095 Mon Sep 17 00:00:00 2001 From: Damian Rouson Date: Sun, 28 Sep 2025 12:43:06 -0700 Subject: [PATCH 1/2] fix #233 - make factories impure fixes #233 Pure functions get_activation_by_name and get_optimizer_by_name construct polymorphic function results. Removing `pure` enables building with the LLVM flang-new compiler. Although Fortran 2003 allowed pure functions with allocatable polymorphic results, subsequent standards disallowed such functions. Using this Fortran 2003 feature blocks building with the LLVM and NAG compilers and likely will block building with future versions of gfortran once GCC issue 78640 has been fixed. (See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78640.) TODO: A subsequent error still blocks building with NAG, which this commit does not address. --- src/nf/nf_activation.f90 | 2 +- src/nf/nf_optimizers.f90 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nf/nf_activation.f90 b/src/nf/nf_activation.f90 index 6509a7da..a0ed43ef 100644 --- a/src/nf/nf_activation.f90 +++ b/src/nf/nf_activation.f90 @@ -733,7 +733,7 @@ pure function eval_3d_celu_prime(self, x) result(res) end function eval_3d_celu_prime ! Utility Functions - pure function get_activation_by_name(activation_name) result(res) + function get_activation_by_name(activation_name) result(res) character(len=*), intent(in) :: activation_name class(activation_function), allocatable :: res diff --git a/src/nf/nf_optimizers.f90 b/src/nf/nf_optimizers.f90 index 269308b2..89a8a6eb 100644 --- a/src/nf/nf_optimizers.f90 +++ b/src/nf/nf_optimizers.f90 @@ -316,7 +316,7 @@ end subroutine minimize_adagrad ! Utility Functions !! Returns the default optimizer corresponding to the provided name - pure function get_optimizer_by_name(optimizer_name) result(res) + function get_optimizer_by_name(optimizer_name) result(res) character(len=*), intent(in) :: optimizer_name class(optimizer_base_type), allocatable :: res From fed527be7fa3080cd5e28a1166e5ee467b69c493 Mon Sep 17 00:00:00 2001 From: Damian Rouson Date: Sun, 28 Sep 2025 13:45:05 -0700 Subject: [PATCH 2/2] doc(README): explain parallel testing with flang This commit adds instructions for building and running neural-fortran (specifcally the test suite) using the experimental multi-image capabilities of LLVM flang 22 + the Caffeine parallel runtime library as an alternative to gfortran + OpenCoarrays. --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 5dbda06b..b475d8a1 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,20 @@ in parallel, respectively: fpm build --compiler caf --profile release --flag "-cpp -DPARALLEL" ``` +An experimental capability exists for parallel runs when building with LLVM `flang-new` +version 22 or later and [Caffeine](https://go.lbl.gov/caffeine). Steps for installing +LLVM 22.0.0git (the llvm-project main branch as of this writing) and Caffeine are +outlined in [parallel-testing-with-flang.md]. Once installed, an `fpm` command of the +following form should launch the neural-fortran test suite with two executing images: + +``` +GASNET_PSHM_NODES=2 \ + fpm test \ + --compiler flang-new \ + --flag "-O3 -fcoarray -DPARALLEL" \ + --link-flag "-lcaffeine -lgasnet-smp-seq -L/lib -L/lib" +``` + #### Testing with fpm ``` @@ -305,3 +319,5 @@ group. Neural-fortran has been used successfully in over a dozen published studies. See all papers that cite it [here](https://scholar.google.com/scholar?cites=7315840714744905948). + +https://github.com/BerkeleyLab/julienne/blob/e9f7ea8069206bfc4abf6a9e6dbbd7d07bda075a/doc/parallel-testing-with-flang.md