MarDiehl / stdlib_os

MIT License
12 stars 2 forks source link

Fails to compile with PGI #6

Closed awvwgk closed 3 years ago

awvwgk commented 3 years ago

Project fails to compile with the PGI compilers. Tested on a Manjaro Linux (cmake 3.18.4, ninja 1.10.1, NVHPC 20.9).

NVHPC 20.9:

  1. Install with
    wget https://developer.download.nvidia.com/hpc-sdk/20.9/nvhpc_2020_209_Linux_x86_64_cuda_11.0.tar.gz
    tar xpzf nvhpc_2020_209_Linux_x86_64_cuda_11.0.tar.gz
    NVHPC_SILENT=true NVHPC_INSTALL_DIR=/opt/nvidia/hpc_sdk NVHPC_INSTALL_TYPE=single sudo nvhpc_2020_209_Linux_x86_64_cuda_11.0/install
  2. Load the PGI compilers with
    module use /opt/nvidia/hpc_sdk/modulefiles
    module load nvhpc
  3. Setup build with (-Mbackslash is required with PGI for this project)
    cmake -B _build -G Ninja -DCMAKE_Fortran_FLAGS=-Mbackslash
  4. Build fails with ninja -C _build
    FAILED: src/CMakeFiles/stdlib_test.dir/Linux/os_path.f90.o 
    /opt/nvidia/hpc_sdk/Linux_x86_64/20.9/compilers/bin/nvfortran -I../src/Linux -I. -module src -c src/CMakeFiles/stdlib_test.dir/Linux/os_path.f90-pp.f90 -o src/CMakeFiles/stdlib_test.dir/Linux/os_path.f90.o
    NVFORTRAN-F-0004-Unable to open MODULE file os_path.mod (../src/Linux/../Posix/os_path.f90: 1)
    NVFORTRAN/x86-64 Linux 20.9-0: compilation aborted
  5. Fixing this by cp src/{Posix,Linux}/os_path.f90 leads to
    FAILED: src/CMakeFiles/stdlib_test.dir/Linux/os_path.f90.o src/os_path-os_path.mod 
    /opt/nvidia/hpc_sdk/Linux_x86_64/20.9/compilers/bin/nvfortran -I../src/Linux -I. -Mbackslash -module src -c src/CMakeFiles/stdlib_test.dir/Linux/os_path.f90-pp.f90 -o src/CMakeFiles/stdlib_test.dir/Linux/os_path.f90.o
    NVFORTRAN-S-0310-SELECTCASE expression must be integer, logical, or character  (../src/Linux/os_path.f90: 15)
    0 inform,   0 warnings,   1 severes, 0 fatal for isabs
    NVFORTRAN-S-0155-Could not resolve generic procedure join (../src/Linux/os_path.f90: 42)
    NVFORTRAN-S-0146-Expression must be character type (../src/Linux/os_path.f90: 47)
    NVFORTRAN-S-0155-Could not resolve generic procedure join (../src/Linux/os_path.f90: 52)
    NVFORTRAN-S-0146-Expression must be character type (../src/Linux/os_path.f90: 76)
    NVFORTRAN-F-0084-Illegal use of symbol   (../src/Linux/os_path.f90: 76)
    NVFORTRAN/x86-64 Linux 20.9-0: compilation aborted
arjenmarkus commented 3 years ago

Odd, it looks as if the parameter os_id was not defined - but it is imported via "use os". Is this another problem of compilers not quite supporting submodules? I have seen something of the kind with gfortran under MinGW. There the function trim_sep was not recognised, but when I defined it as public instead of private, the problem was gone. In this case the parameter is public. Maybe include the relevant file (os.name) in src/Posix/os_path.f90?

Op za 21 nov. 2020 om 11:03 schreef Sebastian Ehlert < notifications@github.com>:

Project fails to compile with the PGI compilers. Tested on a Manjaro Linux.

NVHPC 20.9:

  1. Install with

wget https://developer.download.nvidia.com/hpc-sdk/20.9/nvhpc_2020_209_Linux_x86_64_cuda_11.0.tar.gz tar xpzf nvhpc_2020_209_Linux_x86_64_cuda_11.0.tar.gz NVHPC_SILENT=true NVHPC_INSTALL_DIR=/opt/nvidia/hpc_sdk NVHPC_INSTALL_TYPE=single sudo nvhpc_2020_209_Linux_x86_64_cuda_11.0/install

  1. Load the PGI compilers with

module use /opt/nvidia/hpc_sdk/modulefiles module load nvhpc

  1. Setup build with (-Mbackslash is required with PGI for this project)

cmake -B _build -G Ninja -DCMAKE_Fortran_FLAGS=-Mbackslash

  1. Build fails with ninja -C _build

FAILED: src/CMakeFiles/stdlib_test.dir/Linux/os_path.f90.o /opt/nvidia/hpc_sdk/Linux_x86_64/20.9/compilers/bin/nvfortran -I../src/Linux -I. -module src -c src/CMakeFiles/stdlib_test.dir/Linux/os_path.f90-pp.f90 -o src/CMakeFiles/stdlib_test.dir/Linux/os_path.f90.o NVFORTRAN-F-0004-Unable to open MODULE file os_path.mod (../src/Linux/../Posix/os_path.f90: 1) NVFORTRAN/x86-64 Linux 20.9-0: compilation aborted

  1. Fixing this by cp src/{Posix,Linux}/os_path.f90 leads to

FAILED: src/CMakeFiles/stdlib_test.dir/Linux/os_path.f90.o src/os_path-os_path.mod /opt/nvidia/hpc_sdk/Linux_x86_64/20.9/compilers/bin/nvfortran -I../src/Linux -I. -Mbackslash -module src -c src/CMakeFiles/stdlib_test.dir/Linux/os_path.f90-pp.f90 -o src/CMakeFiles/stdlib_test.dir/Linux/os_path.f90.o NVFORTRAN-S-0310-SELECTCASE expression must be integer, logical, or character (../src/Linux/os_path.f90: 15) 0 inform, 0 warnings, 1 severes, 0 fatal for isabs NVFORTRAN-S-0155-Could not resolve generic procedure join (../src/Linux/os_path.f90: 42) NVFORTRAN-S-0146-Expression must be character type (../src/Linux/os_path.f90: 47) NVFORTRAN-S-0155-Could not resolve generic procedure join (../src/Linux/os_path.f90: 52) NVFORTRAN-S-0146-Expression must be character type (../src/Linux/os_path.f90: 76) NVFORTRAN-F-0084-Illegal use of symbol (../src/Linux/os_path.f90: 76) NVFORTRAN/x86-64 Linux 20.9-0: compilation aborted

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/MarDiehl/stdlib_os/issues/6, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN6YR2P64KPHZIBVPD22MLSQ6F77ANCNFSM4T5V7SZQ .

awvwgk commented 3 years ago

The issue seems to be related to the wrong/poor handling of submodules.

Copying the module procedures to os_path allows to compile and successfully run tests with PGI.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4be1854..fb33805 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,4 +1,4 @@
-file(GLOB sources *.f90 *.c ${CMAKE_SYSTEM_NAME}/*.f90)
+file(GLOB sources *.f90 *.c)

 add_executable(stdlib_test ${sources})
 install (TARGETS stdlib_test RUNTIME DESTINATION bin)
diff --git a/src/os_path.f90 b/src/os_path.f90
index 85e9546..9481d2f 100644
--- a/src/os_path.f90
+++ b/src/os_path.f90
@@ -53,22 +53,6 @@ module os_path
     module procedure join5
   end interface join

-  interface
-
-    module pure function isabs(path)
-      logical                      :: isabs
-      character(len=*), intent(in) :: path
-    end function isabs
-
-    module function relpath(path,start)
-      character(len=*), intent(in)           :: path
-      character(len=*), intent(in), optional :: start
-      character(len=:), allocatable          :: relpath
-    end function relpath
-
-  end interface
-
-
   contains

   function abspath(path)
@@ -679,4 +663,81 @@ module os_path
     enddo
   end function trim_sep

+  pure function isabs(path)
+
+    logical                      :: isabs
+    character(len=*), intent(in) :: path
+
+    if(len(path) == 0) then
+      isabs = .false.
+    else
+      isabs = path(1:1) == sep
+
+      select case (os_id)
+        case( OS_LINUX, OS_DARWIN )
+          ! No action needed
+
+        case( OS_CYGWIN, OS_MSYS, OS_MINGW )
+          if ( .not. isabs) isabs = path(2:3) == ':/' .or. path(2:3) == ':\'
+
+        case default
+          ! No action needed
+      end select
+    endif
+
+  end function isabs
+
+
+  function relpath(path,start)
+
+    character(len=*), intent(in)           :: path
+    character(len=*), intent(in), optional :: start
+    character(len=:), allocatable          :: relpath
+
+    character(len=:), allocatable :: common_, path_, start_
+    integer :: l_common, l_path, i, j
+
+    if(isabs(path)) then
+      path_ = normpath(path)
+    else
+      path_ = normpath(join(getcwd(),path))
+    endif
+    l_path = len(path_)
+
+    if(.not. present(start)) then
+      start_ = getcwd()
+    else
+      if(isabs(start)) then
+        start_ = normpath(start)
+      else
+        start_ = normpath(join(getcwd(),start))
+      endif
+    endif
+
+    common_ = commonpath(start_,path_)
+    l_common = len(common_)
+
+    if(l_path == l_common) then
+      relpath = ''
+    else
+      if(common_ == sep) then
+        relpath = path_(l_common+1:)
+      else
+        relpath = path_(l_common+2:)
+      endif
+    endif
+
+    if(start_ /= common_) then
+      j = 0
+      l_common = max(1,l_common)
+
+      do i = l_common, len(start_(l_common:))
+        if(start_(i:i) == sep) j = j+1
+      enddo
+      relpath = repeat(curdir//curdir//sep,j)//relpath
+    endif
+
+    relpath = normpath(relpath)
+
+  end function relpath
 end module os_path