Commit ff41dc65 authored by Daniel Wortmann's avatar Daniel Wortmann

Major change in cmake configuration

configure.sh script is doing part of the job now
more details should be found in README (later :-) )
parent dcbd4869
cmake_minimum_required(VERSION 2.8)
project(FLEUR LANGUAGES NONE)
project(FLEUR LANGUAGES C Fortran)
#some variables might be set in the environment
set(FLEUR_LIBRARIES ${FLEUR_LIBRARIES} $ENV{FLEUR_LIBRARIES})
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} $ENV{CMAKE_Fortran_FLAGS}")
if (DEFINED ENV{FLEUR_NO_SERIAL})
set(FLEUR_USE_SERIAL false)
else()
set(FLEUR_USE_SERIAL true)
endif()
include("cmake/CompilerConfig.txt")
include("cmake/Architectures.txt")
include("cmake/ReportConfig.txt")
#Here the targets and the files are defined
include("cmake/Files_and_Targets.txt")
#install(TARGETS fleur inpgen DESTINATION bin)
......
set(FLEUR_DEFINITIONS "CPP_DOUBLE")
set(FLEUR_MPI_DEFINITIONS "CPP_DOUBLE")
include("cmake/compilerflags.cmake")
include("cmake/tests/test_XML.cmake")
include("cmake/tests/test_LAPACK.cmake")
include("cmake/tests/test_HDF5.cmake")
include("cmake/tests/test_MPI.cmake")
if (FLEUR_USE_MPI)
include("cmake/tests/test_SCALAPACK.cmake")
include("cmake/tests/test_ELPA.cmake")
endif()
......@@ -30,7 +30,7 @@ include(vgen/CMakeLists.txt)
include(inpgen/CMakeLists.txt)
include(docs/CMakeLists.txt)
include(tests/CMakeLists.txt)
if (${Fleur_uses_MPI})
if (${FLEUR_USE_MPI})
include(mpi/CMakeLists.txt)
endif()
......@@ -59,47 +59,35 @@ set_source_files_properties(${fleur_F77} PROPERTIES Fortran_FORMAT FIXED)
set_source_files_properties(${inpgen_F90} PROPERTIES Fortran_FORMAT FREE)
set_source_files_properties(${inpgen_F77} PROPERTIES Fortran_FORMAT FIXED)
if (${Fleur_uses_serial})
#Serial executables
add_executable(fleur ${fleur_SRC} ${c_filesFleur})
target_link_libraries(fleur ${HDF5_LIBS} ${LAPACK_LIBS})
set_target_properties(fleur PROPERTIES Fortran_MODULE_DIRECTORY fleur_modules COMPILE_OPTIONS -Ifleur_modules)
if (${FLEUR_USE_SERIAL})
#Serial executables
add_executable(fleur ${fleur_SRC} ${c_filesFleur})
target_compile_definitions(fleur PUBLIC ${FLEUR_DEFINITIONS})
target_link_libraries(fleur ${FLEUR_LIBRARIES})
set_target_properties(fleur PROPERTIES Fortran_MODULE_DIRECTORY fleur_modules COMPILE_OPTIONS -Ifleur_modules)
#inpgen executable
add_executable(inpgen ${inpgen_F77} ${inpgen_F90} ${juDFT_SRC_F90} ${c_filesInpgen})
target_compile_definitions(inpgen PUBLIC ${FLEUR_DEFINITIONS})
target_link_libraries(inpgen ${FLEUR_LIBRARIES})
set_target_properties(inpgen PROPERTIES Fortran_MODULE_DIRECTORY inpgen_modules COMPILE_OPTIONS -Iinpgen_modules)
endif()
#parallel executables
if(${Fleur_uses_MPI})
#Preprocessor switches
if (${Fleur_uses_ELEMENTAL})
set(MPI_DEFINITIONS ${MPI_DEFINITION} -DCPP_ELEMENTAL)
endif()
if (${Fleur_uses_SCALAPACK})
set(MPI_DEFINITIONS ${MPI_DEFINITION} -DCPP_SCALAPACK )
endif()
if (${Fleur_uses_ELPA})
set(MPI_DEFINITIONS ${MPI_DEFINITION} -DCPP_ELPA -DCPP_ELPA2 )
endif()
set(MPI_DEFINITIONS -DCPP_MPI -DCPP_EVP ${MPI_DEFINITIONS})
if(${FLEUR_USE_MPI})
#fleur_MPI
add_executable(fleur_MPI ${juDFT_HDF} ${juDFT_SRC_F90} ${fleur_SRC} ${c_filesFleur}
${fleur_SRC_MPI})
target_compile_definitions(fleur_MPI PUBLIC ${MPI_DEFINITIONS})
target_link_libraries(fleur_MPI ${HDF5_LIBS} ${LAPACK_LIBS})
add_executable(fleur_MPI ${juDFT_HDF} ${juDFT_SRC_F90} ${fleur_SRC} ${c_filesFleur} ${fleur_SRC_MPI})
target_compile_definitions(fleur_MPI PUBLIC ${FLEUR_MPI_DEFINITIONS})
target_link_libraries(fleur_MPI ${FLEUR_MPI_LIBRARIES})
set_target_properties(fleur_MPI PROPERTIES Fortran_MODULE_DIRECTORY fleur_MPI_modules COMPILE_OPTIONS -Ifleur_MPI_modules)
endif ()
#inpgen executable
add_executable(inpgen ${inpgen_F77} ${inpgen_F90} ${juDFT_SRC_F90} ${c_filesInpgen})
set_target_properties(inpgen PROPERTIES Fortran_MODULE_DIRECTORY inpgen_modules COMPILE_OPTIONS -Iinpgen_modules)
if (${Fleur_uses_serial})
install(TARGETS fleur
if (${FLEUR_USE_SERIAL})
install(TARGETS fleur inpgen
CONFIGURATIONS Release
DESTINATION bin)
endif()
if (${Fleur_uses_MPI})
if (${FLEUR_USE_MPI})
install(TARGETS fleur_MPI
CONFIGURATIONS Release
DESTINATION bin)
......
message("************Summary***************")
message("Configuration file used:${configfile}")
if (${Fleur_uses_HDF5})
message("Compiling with HDF support")
message("HDF linking:${HDF5_LIBS}")
else()
message("No HDF5 support found:You might want to specify HDF5_ROOT before calling cmake")
endif ()
if(${Fleur_uses_MPI})
message("Including targets for parallel compilation")
if (${Fleur_uses_SCALAPACK})
message("Parallel eigenvalue solver using SCALAPACK")
endif()
if (${Fleur_uses_ELPA})
message("Parallel eigenvalue-solver using ELPA")
endif()
else()
message("No MPI found for parallel compilation")
message("Compiler: ${CMAKE_Fortran_COMPILER}")
message("Flags: ${CMAKE_Fortran_FLAGS}")
message("Libraries:${FLEUR_LIBRARIES}")
message("\nThese Libraries are required:")
message("XML Library found:${FLEUR_USE_XML}")
message("LAPACK Library found:${FLEUR_USE_LAPACK}")
message("\nThese Libraries are optional:")
message("HDF5 Library found:${FLEUR_USE_HDF5}")
message("MPI Library found:${FLEUR_USE_MPI}")
if (FLEUR_USE_MPI)
message("SCALAPACK Library found:${FLEUR_USE_SCALAPACK}")
message("ELPA Library found:${FLEUR_USE_ELPA}")
endif()
message("Compiler:${CMAKE_Fortran_COMPILER}")
message("Git describe:${git_describe}")
message("Git hash:${git_hash}")
message("************-------***************")
#cmake file to set compiler flags for some of the known compilers
execute_process(COMMAND ${CMAKE_Fortran_COMPILER} -v OUTPUT_VARIABLE compilerout ERROR_VARIABLE compilerout)
message(${compilerout})
if (${compilerout} MATCHES ".*ifort.*")
message("Intel Fortran detected")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -mkl -r8 -qopenmp")
set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -xHost -O4")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -C -traceback -O0 -g")
elseif(${compilerout} MATCHES ".*pgf.*")
message("PGI Fortran detected")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -mp -Mr8 -Mr8intrinsics")
set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -fast -O3")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -C -traceback -O0 -g -Mchkstk -Mchkptr")
elseif(${compilerout} MATCHES ".*bgxlf.*")
message("IBM/BG Fortran detected")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qsmp=omp -qnosave -qarch=qp -qtune=qp -qrealsize=8 -qfixed -qsuppress=1520-022 -qessl")
set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -O4 -qsuppress=1500-036")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -O0 -g")
elseif(${compilerout} MATCHES ".*gfort.*")
message("gfortran detected")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-none -fopenmp -fdefault-real-8 ")
set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -O4")
set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -O0 -g")
endif()
#This file contains the defaults for compiling FLEUR on known machines
#please add further definitions here and also add code below!
read -r -d '' known_machines << EOM
IFF -- cluster @ PGI of FZJ
JURECA -- @JSC
JUQUEEN -- @JSC
CLAIX -- @RWTH
MARCONI -- @CINECA
EOM
function configure_machine(){
if [ "$machine" = "JURECA" ]
then
echo "JURECA configuration used"
if module list 2>&1 |grep -q intel-para
then
echo "Intel toolchain used"
if module list 2>&1| grep -q Python/2.7.12
then
echo "Python module loaded for XML (OK)"
else
echo "You have to load the Python module"
echo "module load Python/2.7.12"
exit
fi
module load ELPA/2016.05.003-hybrid
module load HDF5
export CC=mpicc
export FC=mpif90
export CMAKE_Fortran_FLAGS="$CMAKE_Fortran_FLAGS -I$EBROOTELPA/include/elpa_openmp-2015.11.001/modules -I$EBROOTHDF5/include -mkl"
export FLEUR_LIBRARIES="$FLEUR_LIBRARIES;-L$EBROOTELPA/lib;-lelpa_openmp;-lmkl_scalapack_lp64;-lmkl_blacs_intelmpi_lp64;-L$EBROOTHDF5/lib;-lhdf5;-lhdf5_fortran"
elif module list 2>&1 |grep -q PGI
then
echo "PGI toolchain used"
echo "Needs to be configured"
exit
else
echo "You have to load the correct modules for compiling"
echo " a) intel-para, python/1.7.12"
echo " or"
echo " b) PGI"
exit
fi
# JUQUEEN
elif [ "$machine" = "JUQUEEN" ]
then
echo "JUQUEEN configuration used"
module load hdf5/1.8.15_BGQ
module load scalapack/2.0.2_elpa_simd
export CC=mpixlc
export FC=mpixlf2008_r
export CMAKE_Fortran_FLAGS="$CMAKE_Fortran_FLAGS -I${HDF5_DIR}/include -I${ELPA_INCLUDE}"
export FLEUR_LIBRARIES="$FLEUR_LIBRARIES;-L$SCALAPACK_ROOT/lib;-lelpa;-lscalapack;-L/bgsys/local/lapack/3.3.0_g/lib;-llapack;-L/bgsys/local/lib;-qessl;-lesslsmpbg;-L$XML2LIB;-lxml2;-L${HDF5_DIR}/lib;-lhdf5_fortran;-lhdf5;-L/bgsys/local/zlib/lib/;-lz;-L/bgsys/local/szip/lib/;-lsz"
#IFF linux cluster
elif [ "$machine" = "IFF" ]
then
echo "IFF cluster configuration used"
export FC=mpiifort
export FLEUR_LIBRARIES="$FLEUR_LIBRARIES;-lmkl_scalapack_lp64;-lmkl_blacs_intelmpi_lp64"
#RWTH cluster
elif [ "$machine" = "CLAIX" ]
then
echo "CLAIX@RWTH configuration used"
if ! module list 2>&1| grep -q intelmpi
then
echo "Please use intelmpi, e.g. do a module switch openmpi intelmpi"
exit
fi
module load LIBRARIES
module load hdf5
export FC=mpiifort
export FLEUR_LIBRARIES="$FLEUR_LIBRARIES;-lmkl_scalapack_lp64;-lmkl_blacs_intelmpi_lp64"
elif [ "$machine" = "MARCONI" ]
then
if ! module list 2>&1| grep -q " intel\/" || ! module list 2>&1| grep -q " intelmpi" ||! module list 2>&1| grep -q cmake
then
echo "Load the modules needed to compile: intel,intelmpi,cmake"
exit
fi
export FC=mpif90
export FLEUR_LIBRARIES="$FLEUR_LIBRARIES;-lmkl_scalapack_lp64;-lmkl_blacs_intelmpi_lp64"
elif [ "$machine" = "AUTO" ]
then
echo "No machine specific settings used"
echo "GOOD LUCK!"
else
echo "No valid machine configuration specified"
exit
fi
}
#First check if we can compile with ELPA
try_compile(FLEUR_USE_ELPA ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_ELPA.f90
LINK_LIBRARIES ${FLEUR_LIBRARIES}
)
message("ELPA Library found:${FLEUR_USE_ELPA}")
if (FLEUR_USE_ELPA)
set(FLEUR_MPI_DEFINITIONS ${FLEUR_MPI_DEFINITIONS} "CPP_ELPA")
endif()
\ No newline at end of file
program test
use elpa1
integer:: ierr,mpi_subcom, myrowblacs, mycolblacs
integer:: mpi_comm_rows,mpi_comm_cols
ierr=get_elpa_row_col_comms(mpi_subcom, myrowblacs, mycolblacs, &
& mpi_comm_rows, mpi_comm_cols)
end
#first try if hdf already works
try_compile(FLEUR_USE_HDF5 ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_HDF5.f90
LINK_LIBRARIES ${FLEUR_LIBRARIES}
)
#now try to find the library using HDF5_ROOT variable
if (NOT FLEUR_USE_HDF5)
if (DEFINED ENV{HDF5_ROOT})
find_path(HDF5_INCLUDE hdf5.mod PATHS $ENV{HDF5_ROOT} PATH_SUFFIXES include NO_DEFAULT_PATH)
find_path(HDF5_LIB libhdf5_fortran.a PATHS $ENV{HDF5_ROOT} PATH_SUFFIXES lib NO_DEFAULT_PATH)
if (HDF5_LIB)
set(TEST_LIBRARIES "-L${HDF5_LIB};-lhdf5_fortran;-lhdf5;${FLEUR_LIBRARIES}")
endif()
if (HDF5_INCLUDE)
set(STORE_FLAGS ${CMAKE_Fortran_FLAGS})
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -I${HDF5_INCLUDE}")
endif()
try_compile(FLEUR_USE_HDF5 ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_HDF5.f90
LINK_LIBRARIES ${TEST_LIBRARIES}
)
if (NOT FLEUR_USE_HDF5)
set(CMAKE_Fortran_FLAGS ${STORE_FLAGS})
else()
set(FLEUR_LIBRARIES "-L${HDF5_LIB};-lhdf5_fortran;-lhdf5;${FLEUR_LIBRARIES}")
set(FLEUR_MPI_LIBRARIES "-L${HDF5_LIB};-lhdf5_fortran;-lhdf5;${FLEUR_MPI_LIBRARIES}")
endif()
endif()
endif()
#now try the find_package feature
if (NOT FLEUR_USE_HDF5)
find_package(HDF5)
if (NOT HDF5_LIBRARIES MATCHES "NOTFOUND")
set(TEST_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${FLEUR_LIBRARIES})
set(STORE_FLAGS ${CMAKE_Fortran_FLAGS})
set(CMAKE_Fortran_FLAGS "-I${HDF5_INCLUDE_LIBRARIES}" ${CMAKE_Fortran_FLAGS})
try_compile(FLEUR_USE_HDF5 ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_HDF5.f90
LINK_LIBRARIES ${TEST_LIBRARIES}
)
if (${FLEUR_USE_HDF5})
set(FLEUR_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${FLEUR_LIBRARIES})
set(FLEUR_MPI_LIBRARIES ${HDF5_Fortran_LIBRARIES} ${FLEUR_MPI_LIBRARIES})
else()
set(CMAKE_Fortran_FLAGS ${STORE_FLAGS})
endif()
endif()
endif()
message("HDF5 Library found:${FLEUR_USE_HDF5}")
if (FLEUR_USE_HDF)
set(FLEUR_DEFINITIONS ${FLEUR_DEFINITIONS} "CPP_HDF")
set(FLEUR_MPI_DEFINITIONS ${FLEUR_MPI_DEFINITIONS} "CPP_HDF")
endif()
\ No newline at end of file
program test
use hdf5
integer:: error
CALL h5open_f(error)
CALL h5close_f(error)
end
#First check if we can compile with LAPACK
try_compile(FLEUR_USE_LAPACK ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_LAPACK.f90
LINK_LIBRARIES ${FLEUR_LIBRARIES}
)
if (NOT FLEUR_USE_LAPACK)
find_package(LAPACK)
set(TEST_LIBRARIES ${FLEUR_LIBRARIES} ${LAPACK_LIBRARIES})
try_compile(FLEUR_USE_LAPACK ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_LAPACK.f90
LINK_LIBRARIES ${TEST_LIBRARIES}
)
if (FLEUR_USE_LAPACK)
set(FLEUR_LIBRARIES ${FLEUR_LIBRARIES} ${LAPACK_LIBRARIES})
set(FLEUR_MPI_LIBRARIES ${FLEUR_MPI_LIBRARIES} ${LAPACK_LIBRARIES})
endif()
endif()
message("LAPACK Library found:${FLEUR_USE_LAPACK}")
\ No newline at end of file
program test
real a(2,2),work(2),w(2)
integer info
call ssyev('N','U',2,a,2,w,work,2,info)
end
#Check if we can compile with MPI
try_compile(FLEUR_USE_MPI ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_MPI.f90
LINK_LIBRARIES ${FLEUR_LIBRARIES}
)
message("MPI Library found:${FLEUR_USE_MPI}")
if (FLEUR_USE_MPI)
set(FLEUR_MPI_DEFINITIONS ${FLEUR_MPI_DEFINITIONS} "CPP_MPI")
endif()
\ No newline at end of file
program test
include 'mpif.h'
integer:: rank,ierr
call MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr)
end
#First check if we can compile with LAPACK
try_compile(FLEUR_USE_SCALAPACK ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_SCALAPACK.f90
LINK_LIBRARIES ${FLEUR_LIBRARIES}
)
message("SCALAPACK Library found:${FLEUR_USE_SCALAPACK}")
if (FLEUR_USE_SCALAPACK)
set(FLEUR_MPI_DEFINITIONS ${FLEUR_MPI_DEFINITIONS} "CPP_SCALAPACK")
endif()
\ No newline at end of file
program test
!call a blacs routine
CALL BLACS_PINFO(1,1)
CALL pzhegvx(1,'V','I','U',1,1.0,1,1,(/1,1/),1.0)
end
#First check if we can compile with XML2
try_compile(FLEUR_USE_XML ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_XML.f90
LINK_LIBRARIES ${FLEUR_LIBRARIES}
)
if (NOT FLEUR_USE_XML)
find_package(LibXml2)
set(CMAKE_C_FLAGS "-I${LIBXML2_INCLUDE_DIR}")
set(TEST_LIBRARIES ${FLEUR_LIBRARIES} ${LIBXML2_LIBRARIES})
try_compile(FLEUR_USE_XML ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake/tests/test_XML.f90
LINK_LIBRARIES ${TEST_LIBRARIES}
)
if (FLEUR_USE_XML)
set(FLEUR_LIBRARIES ${LIBXML2_LIBRARIES} ${FLEUR_LIBRARIES})
set(FLEUR_MPI_LIBRARIES ${LIBXML2_LIBRARIES} ${FLEUR_MPI_LIBRARIES})
endif()
endif()
message("XML Library found:${FLEUR_USE_XML}")
if (FLEUR_USE_XML)
set(FLEUR_DEFINITIONS ${FLEUR_DEFINITIONS} "CPP_XML")
set(FLEUR_MPI_DEFINITIONS ${FLEUR_MPI_DEFINITIONS} "CPP_XML")
endif()
\ No newline at end of file
program test
integer:: i
interface
function xml()bind(C,name="xmlInitParser")
use iso_c_binding
INTEGER(c_int) xmlInitParser
end function xml
end interface
i=xml()
end program test
#!/usr/bin/env bash
echo "------------ Welcome to the FLEUR configuration script -------------"
. cmake/machines.sh
#check if -h or --help was given as argument
if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]
then
echo "USAGE: configure.sh MACHINE"
echo "
To help the script finding a proper configuration you should
provide the name of a specific machine to compile on.
Currently known machine configurations are:
"
echo " $known_machines"
echo "
If you do not find a proper choice you might try
'./configuration.sh AUTO'
You might also want to add your configuration to the file
cmake/machines.sh in this case :-)
In addition you can modify some environment variables:
FLEUR_NO_SERIAL -- if defined no serial executables will be build
FC -- name of Fortran compiler
CC -- name of C compiler
FLEUR_LIBRARIES -- list of linker arguments i.e. '-L/lib;-lbla'
CMAKE_Fortran_FLAGS -- list of compiler options i.e. '-r8'"
fi
#Check if we are using the git version and ask if we want to update
if test -d .git
then
#We are using the git version so ask the user (for 10sec)
echo "Shall we try to update to the newest git version? (y/n)"
read -n 1 -t 10 x
if test "$x" == "y"
then
git pull
fi
fi
#Now check the machine and set some defaults
machine=$1
configure_machine
#include a configfile if present
if test -r config.sh
then
. config.sh
fi
#check if there is a build directory
if test -d build
then
echo "OLD build directory found, saved in build.$$"
mv build build.$$
fi
mkdir build
cd build
#run cmake
cmake ..
......@@ -10,17 +10,17 @@ diagonalization/zsymsecloc.F90
diagonalization/packed_to_full.f90
diagonalization/magma.F90 )
if (${Fleur_uses_MPI})
if (${FLEUR_USE_MPI})
set(fleur_F90 ${fleur_F90}
diagonalization/ssubredist1.F90
diagonalization/ssubredist2.F90)
if(${Fleur_uses_ELPA})
if(${FLEUR_USE_ELPA})
set(fleur_F90 ${fleur_F90} diagonalization/elpa.F90)
endif()
if(${Fleur_uses_SCALAPACK})
if(${FLEUR_USE_SCALAPACK})
set(fleur_F90 ${fleur_F90} diagonalization/chani.F90)
endif()
if(${Fleur_uses_ELEMENTAL})
if(${FLEUR_USE_ELEMENTAL})
set(fleur_F90 ${fleur_F90} diagonalization/elemental.F90)
endif()
endif()
......@@ -136,7 +136,7 @@ CONTAINS
ALLOCATE ( asca_r(myrowssca,mycolssca), stat=err )
else
ALLOCATE ( asca_c(myrowssca,mycolssca), stat=err )
end
end if
IF (err.NE.0) THEN
WRITE (*,*) 'In chani an error occured during the allocation of'
WRITE (*,*) 'asca: ',err,' size: ',myrowssca*mycolssca
......@@ -432,8 +432,6 @@ endif
end if
!
!DEALLOCATE ( eigvec)
DEALLOCATE ( asca )
DEALLOCATE ( bsca )
DEALLOCATE ( iblacsnums )
DEALLOCATE ( ihelp )
DEALLOCATE ( iusermap )
......
MODULE m_broyden
USE m_juDFT
!################################################################
! IMIX = 3 : BROYDEN'S FIRST METHOD
! IMIX = 5 : BROYDEN'S SECOND METHOD
! IMIX = 7 : GENERALIZED ANDERSEN METHOD
! sm : input charge density of iteration m
! afterwards update rho(m+1)
! fm : output minus input charge density of iteration m
! sm1 : input charge density of iteration m-1
! fm1 : output minus inputcharge density of iteration m-1
!################################################################
CONTAINS
SUBROUTINE broyden(&
& cell,stars,atoms,vacuum,sphhar,input,noco,oneD,sym,&
& mmap,nmaph,mapmt,mapvac2,nmap,fm,mit,sm,lpot)
#include"cpp_double.h"
USE m_metric
USE m_types
IMPLICIT NONE
TYPE(t_oneD),INTENT(IN) :: oneD
TYPE(t_input),INTENT(IN) :: input
TYPE(t_vacuum),INTENT(IN) :: vacuum
TYPE(t_noco),INTENT(IN) :: noco
TYPE(t_sym),INTENT(IN) :: sym
TYPE(t_stars),INTENT(IN) :: stars
TYPE(t_cell),INTENT(IN) :: cell
TYPE(t_sphhar),INTENT(IN) :: sphhar
TYPE(t_atoms),INTENT(IN) :: atoms
! ..
! .. Scalar Arguments ..
INTEGER, INTENT (IN) :: mmap,nmap
INTEGER, INTENT (IN) :: mapmt,mapvac2
INTEGER, INTENT (INOUT) :: mit
LOGICAL,OPTIONAL,INTENT(IN) :: lpot
! ..
! .. Array Arguments ..
REAL, INTENT (IN) :: fm(nmap)
REAL, INTENT (INOUT) :: sm(nmap)
!-odim
!+odim
! ..
! .. Local Scalars ..
INTEGER i,it,k,nit,npos,iread,nmaph
REAL bm,dfivi,fmvm,smnorm,vmnorm,alphan
LOGICAL :: l_pot
REAL,PARAMETER:: one=1.0,zero=0.0
! ..
! .. Local Arrays ..
REAL, ALLOCATABLE :: am(:)
REAL, ALLOCATABLE :: fm1(:),sm1(:),ui(:),um(:),vi(:),vm(:)
! ..
! .. External Functions ..
REAL CPP_BLAS_sdot
EXTERNAL CPP_BLAS_sdot
! ..
! .. External Subroutines ..
EXTERNAL CPP_BLAS_saxpy,CPP_BLAS_sscal
! ..
dfivi = zero
IF (PRESENT(lpot)) THEN
l_pot=lpot
ELSE
l_pot=.FALSE.
ENDIF
ALLOCATE (fm1(mmap),sm1(mmap),ui(mmap),um(mmap),vi(mmap),vm(mmap))
ALLOCATE ( am(input%maxiter+1) )
!
IF (mit.NE.1) THEN
!
! load input charge density (sm1) and difference of
! in and out charge densities (fm1) from previous iteration (m-1)
REWIND 57
READ (57) mit,alphan,(fm1(i),i=1,nmap),(sm1(i),i=1,nmap)
IF ( ABS(input%alpha-alphan) > 0.0001 ) THEN
WRITE (6,*) 'mixing parameter has been changed; reset'
WRITE (6,*) 'broyden algorithm or set input%alpha to',alphan
CALL juDFT_error("mixing parameter (input) changed", calledby&
& ="broyden")
ENDIF
!
! loop to generate F_m - F_(m-1) ... sm1
! and rho_m - rho_(m-1) .. fm1
!
sm1=sm-sm1
fm1=fm-fm1
END IF
!
! save F_m and rho_m for next iteration
!
REWIND 57
nit = mit +1
IF (nit > input%maxiter+1) nit = 1
WRITE (57) nit,input%alpha,fm,sm
!
IF (mit.EQ.1) THEN
!
! update for rho for mit=1 is straight mixing
! sm = sm + alpha*fm
!
CALL CPP_BLAS_saxpy(nmap,input%alpha,fm,1,sm,1)
ELSE
!
! |vi> = w|vi>
! loop to generate um : um = sm1 + alpha*fm1 - \sum <fm1|w|vi> ui
!
DO k = 1,nmap
um(k) = input%alpha*fm1(k) + sm1(k)
END DO
iread=MIN(mit-1,input%maxiter+1)
DO it = 2,iread
READ (59,rec=it-1) (ui(i),i=1,nmap),(vi(i),i=1,nmap),dfivi
am(it) = CPP_BLAS_sdot(nmap,vi,1,fm1,1)
CALL CPP_BLAS_saxpy(nmap,-am(it),ui,1,um,1)
WRITE(6,FMT='(5x,"<vi|w|Fm> for it",i2,5x,f10.6)')it,am(it)
END DO
!
! ****************************************
! broyden's first method
! ****************************************
!
IF (input%imix.EQ.3) THEN
!
! convolute drho(m) with the metric: |fm1> = w|sm1>
!
CALL metric(&
& cell,atoms,vacuum,sphhar,input,noco,stars,sym,oneD,&
& mmap,nmaph,mapmt,mapvac2,sm1,fm1,l_pot)
!
! calculate the norm of sm1 : <sm1|w|sm1>
smnorm = CPP_BLAS_sdot(nmap,sm1,1,fm1,1)
!
! loop to generate vm = alpha*sm1 - \sum <ui|w|sm1> vi
!
vm(:) = input%alpha*fm1(:)
DO it = 2,iread
READ (59,rec=it-1)(ui(i),i=1,nmap),&
& (vi(i),i=1,nmap),dfivi
bm = CPP_BLAS_sdot(nmap,ui,1,fm1,1)
CALL CPP_BLAS_saxpy(nmap,-bm,vi,1,vm,1)
!write(6,FMT='(5x,"<ui|w|Fm> for it",i2,5x,f10.6)') it, bm
END DO
!
! complete evaluation of vm
! vmnorm = <um|w|sm1>-<sm1|w|sm1>
!
vmnorm = CPP_BLAS_sdot(nmap,fm1,1,um,1) - smnorm
! * if (vmnorm.lt.tol_10) stop
CALL CPP_BLAS_sscal(nmap,one/vmnorm,vm,1)
! write bm(it)
!
ELSE IF (input%imix.EQ.5) THEN
!
! ****************************************
! broyden's second method
! ****************************************
!
! --> multiply fm1 with metric matrix and store in vm: w |fm1>