Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build HPC commonly-used Tools using LLVM Flang #56348

Open
PeixinQiao opened this issue Jul 2, 2022 · 4 comments
Open

Build HPC commonly-used Tools using LLVM Flang #56348

PeixinQiao opened this issue Jul 2, 2022 · 4 comments
Assignees
Labels
build-problem flang Flang issues not falling into any other category

Comments

@PeixinQiao
Copy link
Contributor

PeixinQiao commented Jul 2, 2022

Export Environment variables

$ mkdir install-llvm-flang install-hpc-tools # prepare the installation path
$ export optflags="-O3"
$ export installLLVMFlangPath=/path-to-install-llvm-flang
$ export installHPCToolsPath=/path-to-install-hpc-tools
$ export PATH=$installLLVMFlangPath/bin:$installHPCToolsPath/bin:$PATH
$ export LD_LIBRARY_PATH=$installLLVMFlangPath/lib:$installHPCToolsPath/lib:$LD_LIBRARY_PATH

Build LLVM Flang

$ git clone https://github.com/llvm/llvm-project.git
$ cd llvm-project
$ mkdir build-f18 && cd build-f18
$ cmake -G Ninja -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$installLLVMFlangPath -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS="clang;flang;mlir;openmp" ../llvm-project/llvm
$ ninja -j
$ ninja install

Build OpenMPI

$ wget https://download.open-mpi.org/release/open-mpi/v4.0/openmpi-4.0.3.tar.gz
$ tar xf openmpi-4.0.3.tar.gz
$ cd openmpi-4.0.3
$ mkdir build-f18 && cd build-f18
$ CC=clang CXX=clang++ FC="flang-new -flang-experimental-exec" CFLAGS=$optflags CXXFLAGS=$optflags FCFLAGS=$optflags ../configure --prefix=$installHPCToolsPath --without-knem --without-ucx --enable-pretty-print-stacktrace --enable-orterun-prefix-by-default --enable-mpi1-compatibility
$ cat ../../mpi-libtool.patch
diff --git a/libtool b/libtool
index 8052fda..bf63042 100755
--- a/libtool
+++ b/libtool
@@ -11841,7 +11841,7 @@ no_builtin_flag=""
 pic_flag=""
 
 # How to pass a linker flag through the compiler.
-wl=""
+wl="-Wl,"
 
 # Compiler flag to prevent dynamic linking.
 link_static_flag=""
$ patch -p1 < ../../mpi-libtool.patch
$ make -j
$ make install

Test:

$ cat test.f90 
program hello_world
  use mpi
  !include 'mpif.h'
  integer ierr, num_procs, my_id
  call MPI_INIT ( ierr )
  ! find out my process ID, and how many processes were started.
  call MPI_COMM_RANK (MPI_COMM_WORLD, my_id, ierr)
  call MPI_COMM_SIZE (MPI_COMM_WORLD, num_procs, ierr)
  print *, "Hello world! I'm process ", my_id, " out of ", num_procs, " processes."
  call MPI_FINALIZE ( ierr )
  !stop
end program hello_world
$ mpif90 test.f90 
$ mpirun -n 4 ./a.out
 Hello world! I'm process  0 out of  4 processes.
 Hello world! I'm process  2 out of  4 processes.
 Hello world! I'm process  3 out of  4 processes.
 Hello world! I'm process  1 out of  4 processes.
@PeixinQiao PeixinQiao added flang Flang issues not falling into any other category and removed new issue labels Jul 2, 2022
@PeixinQiao PeixinQiao changed the title Build OpenMPI using LLVM Flang Build HPC commonly used Tools using LLVM Flang Jul 19, 2022
@PeixinQiao
Copy link
Contributor Author

PeixinQiao commented Jul 19, 2022

Build HDF5

$ wget https://github.com/HDFGroup/hdf5/archive/refs/tags/hdf5-1_12_1.tar.gz
$ tar -xf hdf5-hdf5-1_12_1.tar.gz
$ cd hdf5-hdf5-1_12_1
$ cat ../disable-real-2and3.patch 
diff --git a/m4/aclocal_fc.f90 b/m4/aclocal_fc.f90
index e9a11c0..f5bd5aa 100644
--- a/m4/aclocal_fc.f90
+++ b/m4/aclocal_fc.f90
@@ -112,7 +112,7 @@ PROGRAM FC_AVAIL_KINDS
       ENDDO
 
       ! Find real KINDs
-      list_rkinds(num_rkinds)=SELECTED_REAL_KIND(1)
+      list_rkinds(num_rkinds)=4!SELECTED_REAL_KIND(1)
       max_decimal_prec = 1
       prev_rkind=list_rkinds(num_rkinds)
 
@@ -120,7 +120,7 @@ PROGRAM FC_AVAIL_KINDS
          exp: DO jk = 1, 700
             k = SELECTED_REAL_KIND(ik,jk)
             IF(k.LT.0) EXIT exp
-            IF(k.NE.prev_rkind)THEN
+            IF(k.NE.prev_rkind .AND. k.NE.2 .AND. k.NE.3)THEN
                ! Check if we aleady have that kind
                new_kind = .TRUE.
                DO kk = 1, num_rkinds
$ patch -p1 < ../disable-real-2and3.patch
$ mkdir build-f18 && cd build-f18
$ CC=mpicc CXX=mpicxx FC=mpif90 CFLAGS=$optflags CXXFLAGS=$optflags FCFLAGS=$optflags ../configure --prefix=$installHPCToolsPath --enable-shared --enable-static --enable-fortran --enable-parallel --enable-optimization=high
$ cat ../../hdf5-1_12_1-libtool.patch
diff --git a/libtool b/libtool
index 3b86358..e8ca993 100755
--- a/libtool
+++ b/libtool
@@ -11832,7 +11832,7 @@ no_builtin_flag=""
 pic_flag=""
 
 # How to pass a linker flag through the compiler.
-wl=""
+wl="-Wl,"
 
 # Compiler flag to prevent dynamic linking.
 link_static_flag=""
$ patch -p1 < ../../hdf5-1_12_1-libtool.patch
$ make -j
$ make install

@PeixinQiao PeixinQiao self-assigned this Jul 19, 2022
@PeixinQiao PeixinQiao changed the title Build HPC commonly used Tools using LLVM Flang Build HPC commonly-used Tools using LLVM Flang Jul 19, 2022
@PeixinQiao
Copy link
Contributor Author

PeixinQiao commented Sep 13, 2022

Build PNetCDF

$ wget https://parallel-netcdf.github.io/Release/pnetcdf-1.11.2.tar.gz
$ tar -xf pnetcdf-1.11.2.tar.gz
$ cd pnetcdf-1.11.2
$ mkdir build-f18 && cd build-f18
$ CC=mpicc CXX=mpicxx FC=mpif90 CFLAGS=$optflags CXXFLAGS=$optflags FCFLAGS=$optflags FFLAGS=$optflags ../configure --prefix=$installHPCToolsPath --enable-shared --enable-static --enable-fortran --enable-large-file-test
$ make -j
$ make install

@PeixinQiao
Copy link
Contributor Author

Build NetCDF-C

$ wget https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.7.3.tar.gz
$ tar -xf netcdf-c-4.7.3.tar.gz
$ cd netcdf-c-4.7.3
$ mkdir build-f18 && cd build-f18
$ CC=mpicc CFLAGS="$optflags -I$installHPCToolsPath/include" LDFLAGS="$ldflags -L$installLLVMFlangPath/lib -L$installHPCToolsPath/lib" ../configure --prefix=$installHPCToolsPath --build=aarch64-linux --enable-static --enable-shared --with-pic --enable-parallel-tests --enable-pnetcdf --enable-largefile --enable-large-file-tests --disable-dap
$ make -j
$ make install

@PeixinQiao
Copy link
Contributor Author

Build NetCDF-Fortran

$ wget https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.4.5.tar.gz
$ tar -xf netcdf-fortran-4.4.5.tar.gz
$ cd netcdf-fortran-4.4.5
$ mkdir build-f18 && cd build-f18
$ CC=mpicc CFLAGS="$optflags -I$installHPCToolsPath/include" FC=mpif90 FCFLAGS="$optflags -fPIC -I$installHPCToolsPath/include" LDFLAGS="$ldflags -L$installLLVMFlangPath/lib -L$installHPCToolsPath/lib" ../configure --prefix=$installHPCToolsPath --enable-static --enable-shared --with-pic --enable-parallel-tests --enable-largefile --enable-large-file-tests
$ cat ../../netcdf-fortran-libtool.patch 
diff --git a/libtool b/libtool
index 6593284..70d26a6 100755
--- a/libtool
+++ b/libtool
@@ -11691,7 +11691,7 @@ no_builtin_flag=""
 pic_flag=""
 
 # How to pass a linker flag through the compiler.
-wl=""
+wl="-Wl,"
 
 # Compiler flag to prevent dynamic linking.
 link_static_flag=""
@@ -11843,7 +11843,7 @@ no_builtin_flag=""
 pic_flag=""
 
 # How to pass a linker flag through the compiler.
-wl=""
+wl="-Wl,"
 
 # Compiler flag to prevent dynamic linking.
 link_static_flag=""
$ patch -p1 < ../../netcdf-fortran-libtool.patch
$ make -j
$ make install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-problem flang Flang issues not falling into any other category
Projects
None yet
Development

No branches or pull requests

2 participants