From 557af287e427680537e2cc332dbf150b7da0b3fd Mon Sep 17 00:00:00 2001 From: Frederick Stein Date: Sun, 23 Jun 2024 22:49:37 +0200 Subject: [PATCH] Fix initialization of FFTW This also fixes the import of wisdom files if they were created by CP2K. --- src/pw/fft/fftw3_lib.F | 13 +++-- tests/QS/regtest-fftw-wisdom/TEST_FILES | 3 ++ .../test_wisdom_export.inp | 47 +++++++++++++++++++ .../test_wisdom_import.inp | 47 +++++++++++++++++++ tests/TEST_DIRS | 1 + 5 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 tests/QS/regtest-fftw-wisdom/TEST_FILES create mode 100644 tests/QS/regtest-fftw-wisdom/test_wisdom_export.inp create mode 100644 tests/QS/regtest-fftw-wisdom/test_wisdom_import.inp diff --git a/src/pw/fft/fftw3_lib.F b/src/pw/fft/fftw3_lib.F index c2fea24646..f48c560a01 100644 --- a/src/pw/fft/fftw3_lib.F +++ b/src/pw/fft/fftw3_lib.F @@ -154,9 +154,8 @@ CONTAINS ! only the ionode updates the wisdom IF (ionode) THEN iunit = get_unit_number() - OPEN (UNIT=iunit, FILE=wisdom_file, STATUS="REPLACE", FORM="FORMATTED", ACTION="WRITE", IOSTAT=istat) + OPEN (UNIT=iunit, FILE=wisdom_file, STATUS="UNKNOWN", FORM="FORMATTED", ACTION="WRITE", IOSTAT=istat) IF (istat == 0) THEN - CLOSE (iunit) file_name_length = LEN_TRIM(wisdom_file) ALLOCATE (wisdom_file_name_c(file_name_length + 1)) DO i = 1, file_name_length @@ -166,7 +165,7 @@ CONTAINS isuccess = fftw_export_wisdom_to_filename(wisdom_file_name_c) IF (isuccess == 0) & CPABORT("Error exporting wisdom to file "//wisdom_file) - WRITE (*, *) "Exported wisdom to file "//wisdom_file + CLOSE (iunit) END IF END IF @@ -217,6 +216,10 @@ CONTAINS #include #endif + isuccess = fftw_init_threads() + IF (isuccess == 0) & + CPABORT("Error initializing FFTW with threads") + ! Read FFTW wisdom (if available) ! all nodes are opening the file here... INQUIRE (FILE=wisdom_file, exist=file_exists) @@ -229,8 +232,8 @@ CONTAINS wisdom_file_name_c(file_name_length + 1) = C_NULL_CHAR isuccess = fftw_import_wisdom_from_filename(wisdom_file_name_c) IF (isuccess == 0) & - CPABORT("Error importing wisdom from file "//wisdom_file) - WRITE (*, *) "Imported wisdom to file "//wisdom_file + CALL cp_abort(__LOCATION__, "Error importing wisdom from file "//wisdom_file//". "// & + "Maybe the was created with a different configuration than CP2K is run with.") END IF #if defined (__MKL) diff --git a/tests/QS/regtest-fftw-wisdom/TEST_FILES b/tests/QS/regtest-fftw-wisdom/TEST_FILES new file mode 100644 index 0000000000..b76c4bde35 --- /dev/null +++ b/tests/QS/regtest-fftw-wisdom/TEST_FILES @@ -0,0 +1,3 @@ +test_wisdom_export.inp 11 2e-13 -1.088792073500891 +test_wisdom_import.inp 11 2e-13 -1.088792073500891 +#EOF diff --git a/tests/QS/regtest-fftw-wisdom/test_wisdom_export.inp b/tests/QS/regtest-fftw-wisdom/test_wisdom_export.inp new file mode 100644 index 0000000000..43e5d4d4d3 --- /dev/null +++ b/tests/QS/regtest-fftw-wisdom/test_wisdom_export.inp @@ -0,0 +1,47 @@ +&GLOBAL + FFTW_PLAN_TYPE PATIENT + FFTW_WISDOM_FILE_NAME ./wisdom + PREFERRED_FFT_LIBRARY FFTW3 + PRINT_LEVEL MEDIUM + PROJECT test_wisdom_export + RUN_TYPE ENERGY +&END GLOBAL + +&FORCE_EVAL + METHOD Quickstep + &DFT + BASIS_SET_FILE_NAME BASIS_MOLOPT + POTENTIAL_FILE_NAME GTH_POTENTIALS + &MGRID + CUTOFF 100 + REL_CUTOFF 30 + &END MGRID + &QS + EPS_DEFAULT 1.0E-7 + &END QS + &SCF + EPS_SCF 1.0E-6 + &END SCF + &XC + &XC_FUNCTIONAL PADE + &END XC_FUNCTIONAL + &END XC + &END DFT + &SUBSYS + &CELL + ABC 4.0 3.0 3.0 + MULTIPLE_UNIT_CELL 1 1 1 + &END CELL + &COORD + H 0.0 0.0 0.0 H + H 0.8 0.0 0.0 H + &END COORD + &KIND H + BASIS_SET SZV-MOLOPT-GTH + POTENTIAL GTH-PADE-q1 + &END KIND + &TOPOLOGY + MULTIPLE_UNIT_CELL 1 1 1 + &END TOPOLOGY + &END SUBSYS +&END FORCE_EVAL diff --git a/tests/QS/regtest-fftw-wisdom/test_wisdom_import.inp b/tests/QS/regtest-fftw-wisdom/test_wisdom_import.inp new file mode 100644 index 0000000000..43e5d4d4d3 --- /dev/null +++ b/tests/QS/regtest-fftw-wisdom/test_wisdom_import.inp @@ -0,0 +1,47 @@ +&GLOBAL + FFTW_PLAN_TYPE PATIENT + FFTW_WISDOM_FILE_NAME ./wisdom + PREFERRED_FFT_LIBRARY FFTW3 + PRINT_LEVEL MEDIUM + PROJECT test_wisdom_export + RUN_TYPE ENERGY +&END GLOBAL + +&FORCE_EVAL + METHOD Quickstep + &DFT + BASIS_SET_FILE_NAME BASIS_MOLOPT + POTENTIAL_FILE_NAME GTH_POTENTIALS + &MGRID + CUTOFF 100 + REL_CUTOFF 30 + &END MGRID + &QS + EPS_DEFAULT 1.0E-7 + &END QS + &SCF + EPS_SCF 1.0E-6 + &END SCF + &XC + &XC_FUNCTIONAL PADE + &END XC_FUNCTIONAL + &END XC + &END DFT + &SUBSYS + &CELL + ABC 4.0 3.0 3.0 + MULTIPLE_UNIT_CELL 1 1 1 + &END CELL + &COORD + H 0.0 0.0 0.0 H + H 0.8 0.0 0.0 H + &END COORD + &KIND H + BASIS_SET SZV-MOLOPT-GTH + POTENTIAL GTH-PADE-q1 + &END KIND + &TOPOLOGY + MULTIPLE_UNIT_CELL 1 1 1 + &END TOPOLOGY + &END SUBSYS +&END FORCE_EVAL diff --git a/tests/TEST_DIRS b/tests/TEST_DIRS index 0262fe27c5..6ad77ebf80 100644 --- a/tests/TEST_DIRS +++ b/tests/TEST_DIRS @@ -3,6 +3,7 @@ # Directories have been reordered according the execution time needed for a gfortran pdbg run using 2 MPI tasks # in case a new directory is added just add it at the top of the list.. # the order will be regularly checked and modified... +QS/regtest-fftw-wisdom fftw3 Fist/regtest-water QS/regtest-ecp libgrpp QS/regtest-ecp-2 libgrpp