Mentions légales du service

Skip to content
Snippets Groups Projects
Commit f45a9c13 authored by PRUVOST Florent's avatar PRUVOST Florent
Browse files

add an example about fortran linking

parent 4b83ad0d
No related branches found
No related tags found
No related merge requests found
......@@ -17,10 +17,11 @@ elseif (MORSE_CHAMELEON_USE_STARPU)
endif()
if (MORSE_DISTRIB_DIR)
set( MORSE_CMAKE_MODULE_DIR "${MORSE_DISTRIB_DIR}/cmake_modules/morse" CACHE PATH
"Directory where to find MORSE CMake modules (cmake_modules/morse)")
set( MORSE_CMAKE_MODULE_DIR "${MORSE_DISTRIB_DIR}/morse_cmake/modules" CACHE PATH
"Directory where to find MORSE CMake modules (morse_cmake/modules)")
list(APPEND CMAKE_MODULE_PATH "${MORSE_CMAKE_MODULE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${MORSE_CMAKE_MODULE_DIR}/find")
message(STATUS "MORSE_CMAKE_MODULE_DIR : ${MORSE_CMAKE_MODULE_DIR}/morse_cmake/modules")
include(MorseInit)
# Detect CHAMELEON
......@@ -39,8 +40,10 @@ if (MORSE_DISTRIB_DIR)
endif()
# link_chameleon exe
add_executable(link_chameleon link_chameleon.c)
target_link_libraries(link_chameleon ${CHAMELEON_LIBRARIES_DEP})
add_executable(link_chameleon_c link_chameleon.c)
target_link_libraries(link_chameleon_c ${CHAMELEON_LIBRARIES_DEP})
add_executable(link_chameleon_f link_chameleon.f90)
target_link_libraries(link_chameleon_f ${CHAMELEON_LIBRARIES_DEP})
else()
message(STATUS "MORSE_DISTRIB_DIR is not set")
message(STATUS "Please indicate where is located your MORSE distribution directory."
......
#+TITLE: How to link with Chameleon
#+LANGUAGE: en
#+OPTIONS: H:3 num:t \n:nil @:t ::t |:t _:nil ^:nil -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil pri:nil tags:not-in-toc html-style:nil
Install Chameleon and its dependencies
#+begin_src
# load an environment with dependencies available
# for example
spack install chameleon@master
spack load openblas
spack load hwloc
spack load starpu
spack load chameleon
# alternativaly use pkg-config and/or update your CPATH and LD_LIBRARY_PATH
# for example
export PKG_CONFIG_PATH=/where/is/installed/chameleon/lib/pkgconfig:$PKG_CONFIG_PATH
#+end_src
Example to link with chameleon in CMake project, see the
~CMakeLists.txt~ file
#+begin_src
mkdir build
cd build
cmake .. -DMORSE_DISTRIB_DIR=$PWD/../../cmake_modules -DMORSE_CHAMELEON_USE_STARPU=ON
make VERBOSE=1
./link_chameleon_c
./link_chameleon_f
#+end_src
Example using directly the pkg-config file
#+begin_src
gcc `pkg-config --cflags chameleon` -o link_chameleon_c link_chameleon.c `pkg-config --libs --static chameleon`
gfortran `pkg-config --cflags chameleon` -o link_chameleon_f link_chameleon.f90 `pkg-config --libs --static chameleon`
#+end_src
program fortran_example
implicit none
include 'morse_fortran.h'
integer, parameter:: dp=kind(0.d0) ! double precision
integer, parameter :: NCPU=2, NGPU=0
integer, parameter :: N=500, NRHS=1
double precision, dimension(N*N) :: A, Acpy
double precision, dimension(N*NRHS) :: B, X
double precision :: anorm, bnorm, xnorm, res, eps=1.11022d-16
integer :: info
integer :: UPLO=MorseUpper
logical :: hres
! Initialize MORSE with main parameters
call MORSE_Init(NCPU, NGPU, info)
! generate A matrix with random values such that it is spd
call MORSE_dplgsy( dfloat(N), MorseUpperLower, N, A, N, 51, info )
Acpy = A
! generate RHS
call MORSE_dplrnt( N, NRHS, B, N, 5673, info )
X = B
call MORSE_dpotrf( UPLO, N, A, N, INFO )
call MORSE_dpotrs( UPLO, N, NRHS, A, N, X, N, info)
! compute norms to check the result
call MORSE_dlange( MorseInfNorm, N, N, Acpy, N, anorm)
call MORSE_dlange( MorseInfNorm, N, NRHS, B, N, bnorm)
call MORSE_dlange( MorseInfNorm, N, NRHS, X, N, xnorm)
! compute A*X-B, store the result in B
call MORSE_dgemm( MorseNoTrans, MorseNoTrans, N, NRHS, N, 1.d0, Acpy, N, X, N, -1.d0, B, N, info)
call MORSE_dlange( MorseInfNorm, N, NRHS, B, N, res)
! if hres = 0 then the test succeed
! else the test failed
hres = .TRUE.
hres = ( res / N / eps / (anorm * xnorm + bnorm ) > 100.0 )
print *, " ||Ax-b|| ||A|| ||x|| ||b|| ||Ax-b||/N/eps/(||A||||x||+||b||)"
if (hres) then
print *, res, anorm, xnorm, bnorm, res / N / eps / (anorm * xnorm + bnorm ), "FAILURE"
else
print *, res, anorm, xnorm, bnorm, res / N / eps / (anorm * xnorm + bnorm), "SUCCESS"
endif
! Finalize MORSE
call MORSE_Finalize(info)
end program fortran_example
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment