diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21a9d630..9082dcd9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,6 +70,7 @@ jobs: - name: regression tests run: | cd Build + export CTEST_OUTPUT_ON_FAILURE=1 eval "$MAKETEST" cd ../ env: diff --git a/Examples/ComplexMatrix/main.cc b/Examples/ComplexMatrix/main.cc index 94697748..ecac3525 100644 --- a/Examples/ComplexMatrix/main.cc +++ b/Examples/ComplexMatrix/main.cc @@ -7,6 +7,7 @@ using std::string; #include using std::stringstream; #include "ExponentialSolvers.h" +#include "Logging.h" #include "PSMatrix.h" #include "ProcessGrid.h" #include "SolverParameters.h" @@ -96,6 +97,9 @@ int main(int argc, char *argv[]) { // Setup the process grid. NTPoly::ConstructGlobalProcessGrid(MPI_COMM_WORLD, process_rows, process_columns, process_slices, true); + if (NTPoly::GetGlobalIsRoot()) { + NTPoly::ActivateLogger(); + } // Compute the Hermitian Matrix NTPoly::Matrix_ps InMat(input_file); @@ -113,6 +117,9 @@ int main(int argc, char *argv[]) { OMat.WriteToMatrixMarket(exponential_file); // Cleanup + if (NTPoly::GetGlobalIsRoot()) { + NTPoly::DeactivateLogger(); + } NTPoly::DestructGlobalProcessGrid(); MPI_Finalize(); return 0; diff --git a/Examples/ComplexMatrix/main.f90 b/Examples/ComplexMatrix/main.f90 index c6b011fe..54823dae 100644 --- a/Examples/ComplexMatrix/main.f90 +++ b/Examples/ComplexMatrix/main.f90 @@ -5,14 +5,16 @@ PROGRAM ComplexMatrix USE DataTypesModule, ONLY : NTREAL, NTCOMPLEX USE ExponentialSolversModule, ONLY : ComputeExponential - USE LoggingModule, ONLY : EnterSubLog, ExitSubLog, WriteElement, WriteHeader + USE LoggingModule, ONLY : ActivateLogger, DeactivateLogger, EnterSubLog, & + & ExitSubLog, WriteElement, WriteHeader USE MatrixMarketModule, ONLY : MM_SYMMETRIC USE PSMatrixAlgebraModule, ONLY : IncrementMatrix, ScaleMatrix USE PSMatrixModule, ONLY : Matrix_ps, ConstructMatrixFromMatrixMarket, & & DestructMatrix, TransposeMatrix, GetMatrixTripletList, & & FillMatrixFromTripletList, ConstructEmptyMatrix, ConjugateMatrix, & & PrintMatrix, CopyMatrix, WriteMatrixToMatrixMarket - USE ProcessGridModule, ONLY : ConstructProcessGrid, DestructProcessGrid + USE ProcessGridModule, ONLY : ConstructProcessGrid, DestructProcessGrid, & + & IsRoot USE SolverParametersModule, ONLY : SolverParameters_t USE TripletListModule, ONLY : TripletList_r, DestructTripletList, & & GetTripletAt, TripletList_c, ConstructTripletList, & @@ -40,7 +42,6 @@ PROGRAM ComplexMatrix CALL MPI_Init_thread(MPI_THREAD_SERIALIZED, provided, ierr) !! Process The Input - !! Process the input parameters. DO counter=1,COMMAND_ARGUMENT_COUNT(),2 CALL GET_COMMAND_ARGUMENT(counter,argument) CALL GET_COMMAND_ARGUMENT(counter+1,argument_value) @@ -64,6 +65,10 @@ PROGRAM ComplexMatrix CALL ConstructProcessGrid(MPI_COMM_WORLD, process_rows, process_columns, & & process_slices) + !! Write Out Parameters + IF (IsRoot()) THEN + CALL ActivateLogger + END IF CALL WriteHeader("Command Line Parameters") CALL EnterSubLog CALL WriteElement(key="input_file", VALUE=input_file) @@ -89,6 +94,11 @@ PROGRAM ComplexMatrix !! Cleanup CALL DestructMatrix(InMat) CALL DestructMatrix(GMat) + + !! Cleanup + IF (IsRoot()) THEN + CALL DeactivateLogger + END IF CALL DestructProcessGrid CALL MPI_Finalize(ierr) diff --git a/Examples/ComplexMatrix/main.py b/Examples/ComplexMatrix/main.py index 6d52baf2..d51e4ed7 100644 --- a/Examples/ComplexMatrix/main.py +++ b/Examples/ComplexMatrix/main.py @@ -77,6 +77,8 @@ def ConstructGuoMatrix(InMat, OutMat): # Setup the process grid. nt.ConstructGlobalProcessGrid( process_rows, process_columns, process_slices) + if nt.GetGlobalIsRoot(): + nt.ActivateLogger() # Construct The Hermitian Matrix InMat = nt.Matrix_ps(input_file) @@ -92,4 +94,8 @@ def ConstructGuoMatrix(InMat, OutMat): # Write To File OMat.WriteToMatrixMarket(exponential_file) + + # Cleanup + if nt.GetGlobalIsRoot(): + nt.DeactivateLogger() nt.DestructGlobalProcessGrid() diff --git a/Examples/GraphTheory/main.cc b/Examples/GraphTheory/main.cc index d120bc2e..abe996df 100644 --- a/Examples/GraphTheory/main.cc +++ b/Examples/GraphTheory/main.cc @@ -12,6 +12,7 @@ using std::vector; #include // NTPoly Headers #include "InverseSolvers.h" +#include "Logging.h" #include "PSMatrix.h" #include "ProcessGrid.h" #include "SolverParameters.h" @@ -67,6 +68,10 @@ int main(int argc, char *argv[]) { // Setup the process grid. NTPoly::ConstructGlobalProcessGrid(MPI_COMM_WORLD, process_rows, process_columns, process_slices, true); + if (NTPoly::GetGlobalIsRoot()) { + NTPoly::ActivateLogger(); + } + // Set Up The Solver Parameters. NTPoly::SolverParameters solver_parameters; solver_parameters.SetConvergeDiff(convergence_threshold); @@ -166,6 +171,9 @@ int main(int argc, char *argv[]) { ResultMat.WriteToMatrixMarket(output_file); // Cleanup + if (NTPoly::GetGlobalIsRoot()) { + NTPoly::DeactivateLogger(); + } NTPoly::DestructGlobalProcessGrid(); MPI_Finalize(); return 0; diff --git a/Examples/GraphTheory/main.f90 b/Examples/GraphTheory/main.f90 index b40e5dea..a60e28bd 100644 --- a/Examples/GraphTheory/main.f90 +++ b/Examples/GraphTheory/main.f90 @@ -3,7 +3,10 @@ PROGRAM GraphTheory USE DataTypesModule, ONLY : NTREAL USE InverseSolversModule, ONLY : Invert - USE ProcessGridModule, ONLY : ConstructProcessGrid, DestructProcessGrid + USE LoggingModule, ONLY : ActivateLogger, DeactivateLogger, WriteElement, & + & WriteHeader, EnterSubLog, ExitSubLog + USE ProcessGridModule, ONLY : ConstructProcessGrid, DestructProcessGrid, & + & IsRoot USE PSMatrixModule, ONLY : Matrix_ps, WriteMatrixToMatrixMarket, & & ConstructEmptyMatrix, FillMatrixFromTripletList, DestructMatrix, & & CopyMatrix, FillMatrixIdentity @@ -76,6 +79,23 @@ PROGRAM GraphTheory CALL ConstructProcessGrid(MPI_COMM_WORLD, process_rows, process_columns, & & process_slices) + !! Write Out Parameters + IF (IsRoot()) THEN + CALL ActivateLogger + END IF + CALL WriteHeader("Command Line Parameters") + CALL EnterSubLog + CALL WriteElement(key="number_of_nodes", VALUE=number_of_nodes) + CALL WriteElement(key="extra_connections", VALUE=extra_connections) + CALL WriteElement(key="threshold", VALUE=threshold) + CALL WriteElement(key="convergence_threshold", VALUE=convergence_threshold) + CALL WriteElement(key="attenuation", VALUE=attenuation) + CALL WriteElement(key="process_rows", VALUE=process_rows) + CALL WriteElement(key="process_columns", VALUE=process_columns) + CALL WriteElement(key="process_slices", VALUE=process_slices) + CALL WriteElement(key="output_file", VALUE=output_file) + CALL ExitSubLog + !! Set Up The Solver Parameters. solver_parameters = SolverParameters_t( be_verbose_in=.TRUE., & & converge_diff_in=convergence_threshold, threshold_in=threshold) @@ -96,6 +116,11 @@ PROGRAM GraphTheory !! Cleanup CALL DestructMatrix(NetworkMat) CALL DestructMatrix(ResultMat) + + !! Cleanup + IF (IsRoot()) THEN + CALL DeactivateLogger + END IF CALL DestructProcessGrid CALL MPI_Finalize(ierr) CONTAINS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/Examples/GraphTheory/main.py b/Examples/GraphTheory/main.py index 3f436a8e..178f68cc 100644 --- a/Examples/GraphTheory/main.py +++ b/Examples/GraphTheory/main.py @@ -41,6 +41,8 @@ # Setup the process grid. nt.ConstructGlobalProcessGrid( process_rows, process_columns, process_slices) + if nt.GetGlobalIsRoot(): + nt.ActivateLogger() # Set Up The Solver Parameters. solver_parameters = nt.SolverParameters() @@ -133,4 +135,8 @@ # Print the density matrix to file. ResultMat.WriteToMatrixMarket(output_file) + + # Cleanup + if nt.GetGlobalIsRoot(): + nt.DeactivateLogger() nt.DestructGlobalProcessGrid() diff --git a/Examples/HydrogenAtom/main.cc b/Examples/HydrogenAtom/main.cc index a2ac161c..e7276a84 100644 --- a/Examples/HydrogenAtom/main.cc +++ b/Examples/HydrogenAtom/main.cc @@ -11,6 +11,7 @@ using std::vector; #include // NTPoly Headers #include "DensityMatrixSolvers.h" +#include "Logging.h" #include "PSMatrix.h" #include "ProcessGrid.h" #include "SolverParameters.h" @@ -66,6 +67,10 @@ int main(int argc, char *argv[]) { // Setup the process grid. NTPoly::ConstructGlobalProcessGrid(MPI_COMM_WORLD, process_rows, process_columns, process_slices, true); + if (NTPoly::GetGlobalIsRoot()) { + NTPoly::ActivateLogger(); + } + // Set Up The Solver Parameters. NTPoly::SolverParameters solver_parameters; solver_parameters.SetConvergeDiff(convergence_threshold); @@ -163,6 +168,9 @@ int main(int argc, char *argv[]) { Density.WriteToMatrixMarket(density_file_out); // Cleanup + if (NTPoly::GetGlobalIsRoot()) { + NTPoly::DeactivateLogger(); + } NTPoly::DestructGlobalProcessGrid(); MPI_Finalize(); return 0; diff --git a/Examples/HydrogenAtom/main.f90 b/Examples/HydrogenAtom/main.f90 index 255905cc..d026a6b7 100644 --- a/Examples/HydrogenAtom/main.f90 +++ b/Examples/HydrogenAtom/main.f90 @@ -3,7 +3,10 @@ PROGRAM HydrogenAtom USE DataTypesModule, ONLY : NTREAL USE DensityMatrixSolversModule, ONLY : TRS2 - USE ProcessGridModule, ONLY : ConstructProcessGrid, DestructProcessGrid + USE LoggingModule, ONLY : ActivateLogger, DeactivateLogger, WriteHeader, & + & WriteElement, EnterSubLog, ExitSubLog + USE ProcessGridModule, ONLY : ConstructProcessGrid, DestructProcessGrid, & + & IsRoot USE PSMatrixModule, ONLY : Matrix_ps, WriteMatrixToMatrixMarket, & & ConstructEmptyMatrix, FillMatrixFromTripletList, CopyMatrix, & & FillMatrixIdentity @@ -76,6 +79,21 @@ PROGRAM HydrogenAtom CALL ConstructProcessGrid(MPI_COMM_WORLD, process_rows, process_columns, & & process_slices) + !! Write Out Parameters + IF (IsRoot()) THEN + CALL ActivateLogger + END IF + CALL WriteHeader("Command Line Parameters") + CALL EnterSubLog + CALL WriteElement(key="convergence_threshold", VALUE=convergence_threshold) + CALL WriteElement(key="grid_points", VALUE=grid_points) + CALL WriteElement(key="threshold", VALUE=threshold) + CALL WriteElement(key="process_rows", VALUE=process_rows) + CALL WriteElement(key="process_columns", VALUE=process_columns) + CALL WriteElement(key="process_slices", VALUE=process_slices) + CALL WriteElement(key="density_file_out", VALUE=density_file_out) + CALL ExitSubLog + !! Set Up The Solver Parameters. solver_parameters = SolverParameters_t( be_verbose_in=.TRUE., & & converge_diff_in=convergence_threshold, threshold_in=threshold) @@ -110,6 +128,9 @@ PROGRAM HydrogenAtom CALL WriteMatrixToMatrixMarket(Density,density_file_out) !! Cleanup + IF (IsRoot()) THEN + CALL DeactivateLogger + END IF CALL DestructProcessGrid CALL MPI_Finalize(ierr) CONTAINS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/Examples/HydrogenAtom/main.py b/Examples/HydrogenAtom/main.py index 43051fd0..2bc54fdb 100644 --- a/Examples/HydrogenAtom/main.py +++ b/Examples/HydrogenAtom/main.py @@ -39,6 +39,8 @@ # Setup the process grid. nt.ConstructGlobalProcessGrid( process_rows, process_columns, process_slices) + if nt.GetGlobalIsRoot(): + nt.ActivateLogger() # Set Up The Solver Parameters. solver_parameters = nt.SolverParameters() @@ -121,4 +123,8 @@ # Print the density matrix to file. Density.WriteToMatrixMarket(density_file_out) + + # Cleanup + if nt.GetGlobalIsRoot(): + nt.DeactivateLogger() nt.DestructGlobalProcessGrid() diff --git a/Examples/MatrixMaps/main.cc b/Examples/MatrixMaps/main.cc index dd970a73..11288dbd 100644 --- a/Examples/MatrixMaps/main.cc +++ b/Examples/MatrixMaps/main.cc @@ -6,6 +6,7 @@ using std::string; #include using std::stringstream; // NTPoly Headers +#include "Logging.h" #include "MatrixMapper.h" #include "PSMatrix.h" #include "ProcessGrid.h" @@ -53,6 +54,9 @@ int main(int argc, char *argv[]) { // Setup the process grid. NTPoly::ConstructGlobalProcessGrid(MPI_COMM_WORLD, process_slices, true); + if (NTPoly::GetGlobalIsRoot()) { + NTPoly::ActivateLogger(); + } // Read in the matrices from file. NTPoly::Matrix_ps Input(input_file); @@ -66,6 +70,9 @@ int main(int argc, char *argv[]) { Output.WriteToMatrixMarket(output_file); // Cleanup + if (NTPoly::GetGlobalIsRoot()) { + NTPoly::DeactivateLogger(); + } NTPoly::DestructGlobalProcessGrid(); MPI_Finalize(); return 0; diff --git a/Examples/MatrixMaps/main.f90 b/Examples/MatrixMaps/main.f90 index 229f2e9d..1cda234a 100644 --- a/Examples/MatrixMaps/main.f90 +++ b/Examples/MatrixMaps/main.f90 @@ -2,9 +2,11 @@ !> An example which shows how to use the matrix mapping feature of NTPoly. PROGRAM MatrixMapsProgram USE DataTypesModule, ONLY : NTREAL - USE LoggingModule, ONLY : EnterSubLog, ExitSubLog, WriteElement, WriteHeader + USE LoggingModule, ONLY : EnterSubLog, ExitSubLog, ActivateLogger, & + & DeactivateLogger, WriteElement, WriteHeader USE MatrixMapsModule, ONLY : MapMatrix_psr - USE ProcessGridModule, ONLY : ConstructProcessGrid, DestructProcessGrid + USE ProcessGridModule, ONLY : ConstructProcessGrid, DestructProcessGrid, & + & IsRoot USE PSMatrixModule, ONLY : Matrix_ps, ConstructMatrixFromMatrixMarket, & & DestructMatrix, WriteMatrixToMatrixMarket USE MPI @@ -43,6 +45,9 @@ PROGRAM MatrixMapsProgram CALL ConstructProcessGrid(MPI_COMM_WORLD, process_slices) !! Print out parameters. + IF (IsRoot()) THEN + CALL ActivateLogger + END IF CALL WriteHeader("Command Line Parameters") CALL EnterSubLog CALL WriteElement(key="input_matrix", VALUE=input_matrix) @@ -64,6 +69,9 @@ PROGRAM MatrixMapsProgram CALL DestructMatrix(OutMatrix) !! Cleanup + IF (IsRoot()) THEN + CALL DeactivateLogger + END IF CALL DestructProcessGrid CALL MPI_Finalize(ierr) CONTAINS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/Examples/MatrixMaps/main.py b/Examples/MatrixMaps/main.py index 4ef56064..26c4f55a 100644 --- a/Examples/MatrixMaps/main.py +++ b/Examples/MatrixMaps/main.py @@ -37,6 +37,8 @@ def __call__(self): # Setup the process grid. nt.ConstructGlobalProcessGrid(process_slices) + if nt.GetGlobalIsRoot(): + nt.ActivateLogger() # Read in the matrices from file. Input = nt.Matrix_ps(input_matrix) @@ -48,4 +50,8 @@ def __call__(self): # Print the density matrix to file. Output.WriteToMatrixMarket(output_matrix) + + # Cleanup + if nt.GetGlobalIsRoot(): + nt.DeactivateLogger() nt.DestructGlobalProcessGrid() diff --git a/Examples/OverlapMatrix/main.f90 b/Examples/OverlapMatrix/main.f90 index ab1b48dd..4ef7a1c0 100644 --- a/Examples/OverlapMatrix/main.f90 +++ b/Examples/OverlapMatrix/main.f90 @@ -2,9 +2,11 @@ !> An example that shows how to compute the overlap matrix. PROGRAM OverlapExample USE DataTypesModule, ONLY : NTREAL + USE LoggingModule, ONLY : ActivateLogger, DeactivateLogger, WriteElement, & + & WriteHeader, EnterSubLog, ExitSubLog USE PermutationModule, ONLY : Permutation_t, ConstructRandomPermutation, & & DestructPermutation - USE ProcessGridModule, ONLY : ConstructProcessGrid, global_grid, & + USE ProcessGridModule, ONLY : ConstructProcessGrid, IsRoot, global_grid, & & DestructProcessGrid USE PSMatrixModule, ONLY : Matrix_ps, ConstructEmptyMatrix, & & WriteMatrixToMatrixMarket, FillMatrixFromTripletList, DestructMatrix @@ -70,6 +72,20 @@ PROGRAM OverlapExample CALL ConstructProcessGrid(MPI_COMM_WORLD, process_rows, process_columns, & & process_slices) + !! Print Out The Parameters + IF (IsRoot()) THEN + CALL ActivateLogger + END IF + CALL WriteHeader("Command Line Parameters") + CALL EnterSubLog + CALL WriteElement(key="basis_functions", VALUE=basis_functions) + CALL WriteElement(key="convergence_threshold", VALUE=convergence_threshold) + CALL WriteElement(key="threshold", VALUE=threshold) + CALL WriteElement(key="process_rows", VALUE=process_rows) + CALL WriteElement(key="process_columns", VALUE=process_columns) + CALL WriteElement(key="process_slices", VALUE=process_slices) + CALL ExitSubLog + !! Timers CALL RegisterTimer("Construct Triplet List") CALL RegisterTimer("Fill") @@ -128,6 +144,11 @@ PROGRAM OverlapExample CALL DestructPermutation(permutation) CALL DestructMatrix(Overlap) CALL DestructMatrix(ISQOverlap) + + !! Cleanup + IF (IsRoot()) THEN + CALL DeactivateLogger + END IF CALL DestructProcessGrid CALL MPI_Finalize(ierr) CONTAINS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/Examples/PremadeMatrix/main.cc b/Examples/PremadeMatrix/main.cc index 1939e931..a15b0c8a 100644 --- a/Examples/PremadeMatrix/main.cc +++ b/Examples/PremadeMatrix/main.cc @@ -7,6 +7,7 @@ using std::string; using std::stringstream; // NTPoly Headers #include "DensityMatrixSolvers.h" +#include "Logging.h" #include "PSMatrix.h" #include "Permutation.h" #include "ProcessGrid.h" @@ -61,6 +62,9 @@ int main(int argc, char *argv[]) { // Setup the process grid. NTPoly::ConstructGlobalProcessGrid(MPI_COMM_WORLD, process_rows, process_columns, process_slices, true); + if (NTPoly::GetGlobalIsRoot()) { + NTPoly::ActivateLogger(); + } // Read in the matrices from file. NTPoly::Matrix_ps Hamiltonian(hamiltonian_file); @@ -94,6 +98,9 @@ int main(int argc, char *argv[]) { Density.WriteToMatrixMarket(density_file_out); // Cleanup + if (NTPoly::GetGlobalIsRoot()) { + NTPoly::DeactivateLogger(); + } NTPoly::DestructGlobalProcessGrid(); MPI_Finalize(); return 0; diff --git a/Examples/PremadeMatrix/main.f90 b/Examples/PremadeMatrix/main.f90 index 27bb2ff0..34469892 100644 --- a/Examples/PremadeMatrix/main.f90 +++ b/Examples/PremadeMatrix/main.f90 @@ -3,7 +3,8 @@ PROGRAM PremadeMatrixProgram USE DataTypesModule, ONLY : NTREAL USE DensityMatrixSolversModule, ONLY : TRS2 - USE LoggingModule, ONLY : EnterSubLog, ExitSubLog, WriteElement, WriteHeader + USE LoggingModule, ONLY : ActivateLogger, DeactivateLogger, EnterSubLog, & + & ExitSubLog, WriteElement, WriteHeader USE PermutationModule, ONLY : Permutation_t, ConstructRandomPermutation, & & DestructPermutation USE ProcessGridModule, ONLY : ConstructProcessGrid, IsRoot, & @@ -72,6 +73,10 @@ PROGRAM PremadeMatrixProgram CALL ConstructProcessGrid(MPI_COMM_WORLD, process_rows, process_columns, & & process_slices) + !! Write Out Parameters + IF (IsRoot()) THEN + CALL ActivateLogger + END IF CALL WriteHeader("Command Line Parameters") CALL EnterSubLog CALL WriteElement(key="hamiltonian", VALUE=hamiltonian_file) @@ -119,6 +124,9 @@ PROGRAM PremadeMatrixProgram CALL DestructMatrix(Density) !! Cleanup + IF (IsRoot()) THEN + CALL DeactivateLogger + END IF CALL DestructProcessGrid CALL MPI_Finalize(ierr) END PROGRAM PremadeMatrixProgram diff --git a/Examples/PremadeMatrix/main.py b/Examples/PremadeMatrix/main.py index da3c1d8e..aca2257c 100644 --- a/Examples/PremadeMatrix/main.py +++ b/Examples/PremadeMatrix/main.py @@ -39,6 +39,8 @@ # Setup the process grid. nt.ConstructGlobalProcessGrid( process_rows, process_columns, process_slices) + if nt.GetGlobalIsRoot(): + nt.ActivateLogger() # Read in the matrices from file. Hamiltonian = nt.Matrix_ps(hamiltonian_file) @@ -72,4 +74,8 @@ # Print the density matrix to file. Density.WriteToMatrixMarket(density_file_out) + + # Cleanup + if nt.GetGlobalIsRoot(): + nt.DeactivateLogger() nt.DestructGlobalProcessGrid() diff --git a/Source/C/CMakeLists.txt b/Source/C/CMakeLists.txt index 17e67ddd..1cba0702 100644 --- a/Source/C/CMakeLists.txt +++ b/Source/C/CMakeLists.txt @@ -8,6 +8,7 @@ set(Csrc InverseSolvers_c.h LinearSolvers_c.h LoadBalancer_c.h + Logging_c.h MatrixConversion_c.h MatrixMemoryPool_c.h PMatrixMemoryPool_c.h diff --git a/Source/C/Logging_c.h b/Source/C/Logging_c.h new file mode 100644 index 00000000..b85a57dd --- /dev/null +++ b/Source/C/Logging_c.h @@ -0,0 +1,9 @@ +#ifndef Logging_ch +#define Logging_ch + +void ActivateLogger_wrp(const bool *start_document); +void ActivateLoggerFile_wrp(const bool *start_document, const char *file_name, + const int *name_size); +void DeactivateLogger_wrp(); + +#endif diff --git a/Source/C/ProcessGrid_c.h b/Source/C/ProcessGrid_c.h index 68b7d5a7..1a0a071e 100644 --- a/Source/C/ProcessGrid_c.h +++ b/Source/C/ProcessGrid_c.h @@ -15,6 +15,7 @@ void CopyProcessGrid_wrp(const int *ih_old_grid, int *ih_new_grid); int GetGlobalMySlice_wrp(); int GetGlobalMyColumn_wrp(); int GetGlobalMyRow_wrp(); +bool GetGlobalIsRoot_wrp(); int GetGlobalNumSlices_wrp(); int GetGlobalNumColumns_wrp(); int GetGlobalNumRows_wrp(); diff --git a/Source/CPlusPlus/CMakeLists.txt b/Source/CPlusPlus/CMakeLists.txt index 17b4b9ff..708f64b2 100644 --- a/Source/CPlusPlus/CMakeLists.txt +++ b/Source/CPlusPlus/CMakeLists.txt @@ -9,6 +9,7 @@ set(Csrc InverseSolvers.cc LinearSolvers.cc LoadBalancer.cc + Logging.cc MatrixConversion.cc MatrixMapper.cc MatrixMemoryPool.cc @@ -37,6 +38,7 @@ set(Chead InverseSolvers.h LinearSolvers.h LoadBalancer.h + Logging.h MatrixConversion.h MatrixMapper.h MatrixMemoryPool.h diff --git a/Source/CPlusPlus/Logging.cc b/Source/CPlusPlus/Logging.cc new file mode 100644 index 00000000..65c7e3cc --- /dev/null +++ b/Source/CPlusPlus/Logging.cc @@ -0,0 +1,22 @@ +#include "Logging.h" +using std::string; + +//////////////////////////////////////////////////////////////////////////////// +extern "C" { +#include "Logging_c.h" +} + +//////////////////////////////////////////////////////////////////////////////// +void NTPoly::ActivateLogger(bool start_document) { + ActivateLogger_wrp(&start_document); +} + +//////////////////////////////////////////////////////////////////////////////// +void NTPoly::ActivateLogger(const string file_name, bool start_document) { + int string_length = file_name.length(); + string temp = file_name; + ActivateLoggerFile_wrp(&start_document, &temp.c_str()[0], &string_length); +} + +//////////////////////////////////////////////////////////////////////////////// +void NTPoly::DeactivateLogger() { DeactivateLogger_wrp(); } diff --git a/Source/CPlusPlus/Logging.h b/Source/CPlusPlus/Logging.h new file mode 100644 index 00000000..c97e3220 --- /dev/null +++ b/Source/CPlusPlus/Logging.h @@ -0,0 +1,22 @@ +#ifndef Logging_h +#define Logging_h + +#include + +//////////////////////////////////////////////////////////////////////////////// +namespace NTPoly { +//////////////////////////////////////////////////////////////////////////////// +//! Activate the logger. +void ActivateLogger(bool start_document = false); + +//////////////////////////////////////////////////////////////////////////////// +//! Activate the logger with a specific file. +//!\param file_name file to print to. +void ActivateLogger(const std::string file_name, bool start_document = false); + +//////////////////////////////////////////////////////////////////////////////// +//! Deactivate the logger. +void DeactivateLogger(); + +} // namespace NTPoly +#endif diff --git a/Source/CPlusPlus/ProcessGrid.cc b/Source/CPlusPlus/ProcessGrid.cc index ce959fc5..04a736fd 100644 --- a/Source/CPlusPlus/ProcessGrid.cc +++ b/Source/CPlusPlus/ProcessGrid.cc @@ -115,6 +115,9 @@ int GetGlobalMyColumn() { return GetGlobalMyColumn_wrp(); } //////////////////////////////////////////////////////////////////////////////// int GetGlobalMyRow() { return GetGlobalMyRow_wrp(); } +//////////////////////////////////////////////////////////////////////////////// +bool GetGlobalIsRoot() { return GetGlobalIsRoot_wrp(); } + //////////////////////////////////////////////////////////////////////////////// int GetGlobalNumSlices() { return GetGlobalNumSlices_wrp(); } diff --git a/Source/CPlusPlus/ProcessGrid.h b/Source/CPlusPlus/ProcessGrid.h index b5d0727a..6f63ba91 100644 --- a/Source/CPlusPlus/ProcessGrid.h +++ b/Source/CPlusPlus/ProcessGrid.h @@ -99,6 +99,8 @@ int GetGlobalMySlice(); int GetGlobalMyColumn(); //! Get the row of the current process. int GetGlobalMyRow(); +//! Get the current process is root. +bool GetGlobalIsRoot(); //! Get the number of process slices. int GetGlobalNumSlices(); //! Get the number of process columns. diff --git a/Source/Fortran/DensityMatrixSolversModule.F90 b/Source/Fortran/DensityMatrixSolversModule.F90 index 780f5dd3..562bb1b3 100644 --- a/Source/Fortran/DensityMatrixSolversModule.F90 +++ b/Source/Fortran/DensityMatrixSolversModule.F90 @@ -5,7 +5,7 @@ MODULE DensityMatrixSolversModule USE EigenBoundsModule, ONLY : GershgorinBounds USE LoadBalancerModule, ONLY : PermuteMatrix, UndoPermuteMatrix USE LoggingModule, ONLY : WriteElement, WriteListElement, WriteHeader, & - & WriteCitation, EnterSubLog, ExitSubLog + & EnterSubLog, ExitSubLog USE PMatrixMemoryPoolModule, ONLY : MatrixMemoryPool_p, & & DestructMatrixMemoryPool USE PSMatrixAlgebraModule, ONLY : IncrementMatrix, MatrixMultiply, & @@ -77,7 +77,10 @@ SUBROUTINE PM(Hamiltonian, InverseSquareRoot, nel, Density, & CALL WriteHeader("Density Matrix Solver") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="PM") - CALL WriteCitation("palser1998canonical") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("palser1998canonical") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -188,9 +191,8 @@ SUBROUTINE PM(Hamiltonian, InverseSquareRoot, nel, Density, & norm_value = ABS(energy_value - energy_value2) IF (solver_parameters%be_verbose) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter) + CALL WriteListElement(key="Convergence", VALUE=norm_value) CALL EnterSubLog - CALL WriteElement(key="Convergence", VALUE=norm_value) CALL WriteElement("Energy_Value", VALUE=energy_value) CALL ExitSubLog END IF @@ -328,7 +330,10 @@ SUBROUTINE TRS2(Hamiltonian, InverseSquareRoot, nel, Density, & CALL WriteHeader("Density Matrix Solver") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="TRS2") - CALL WriteCitation("niklasson2002expansion") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("niklasson2002expansion") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -405,9 +410,8 @@ SUBROUTINE TRS2(Hamiltonian, InverseSquareRoot, nel, Density, & norm_value = ABS(energy_value - energy_value2) IF (solver_parameters%be_verbose) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter) + CALL WriteListElement(key="Convergence", VALUE=norm_value) CALL EnterSubLog - CALL WriteElement(key="Convergence", VALUE=norm_value) CALL WriteElement("Energy_Value", VALUE=energy_value) CALL ExitSubLog END IF @@ -539,7 +543,10 @@ SUBROUTINE TRS4(Hamiltonian, InverseSquareRoot, nel, Density, & CALL WriteHeader("Density Matrix Solver") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="TRS4") - CALL WriteCitation("niklasson2002expansion") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("niklasson2002expansion") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -636,9 +643,8 @@ SUBROUTINE TRS4(Hamiltonian, InverseSquareRoot, nel, Density, & norm_value = ABS(energy_value - energy_value2) IF (solver_parameters%be_verbose) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter) + CALL WriteListElement(key="Convergence", VALUE=norm_value) CALL EnterSubLog - CALL WriteElement(key="Convergence", VALUE=norm_value) CALL WriteElement("Energy_Value", VALUE=energy_value) CALL ExitSubLog END IF @@ -782,7 +788,10 @@ SUBROUTINE HPCP(Hamiltonian, InverseSquareRoot, nel, Density, & CALL WriteHeader("Density Matrix Solver") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="HPCP") - CALL WriteCitation("truflandier2016communication") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("truflandier2016communication") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -883,9 +892,8 @@ SUBROUTINE HPCP(Hamiltonian, InverseSquareRoot, nel, Density, & norm_value = ABS(energy_value - energy_value2) IF (solver_parameters%be_verbose) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter) + CALL WriteListElement(key="Convergence", VALUE=norm_value) CALL EnterSubLog - CALL WriteElement(key="Convergence", VALUE=norm_value) CALL WriteElement("Energy_Value", VALUE=energy_value) CALL ExitSubLog END IF @@ -1016,7 +1024,10 @@ SUBROUTINE ScaleAndFold(Hamiltonian, InverseSquareRoot, nel, Density, & CALL WriteHeader("Density Matrix Solver") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="Scale and Fold") - CALL WriteCitation("rubensson2011nonmonotonic") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("rubensson2011nonmonotonic") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -1093,9 +1104,8 @@ SUBROUTINE ScaleAndFold(Hamiltonian, InverseSquareRoot, nel, Density, & norm_value = ABS(energy_value - energy_value2) IF (solver_parameters%be_verbose) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter) + CALL WriteListElement(key="Convergence", VALUE=norm_value) CALL EnterSubLog - CALL WriteElement(key="Convergence", VALUE=norm_value) CALL WriteElement("Energy_Value", VALUE=energy_value) CALL ExitSubLog END IF diff --git a/Source/Fortran/EigenBoundsModule.F90 b/Source/Fortran/EigenBoundsModule.F90 index d304f9dc..b6d4d59f 100644 --- a/Source/Fortran/EigenBoundsModule.F90 +++ b/Source/Fortran/EigenBoundsModule.F90 @@ -109,10 +109,7 @@ SUBROUTINE PowerBounds(this,max_value,solver_parameters_in) norm_value = solver_parameters%converge_diff + 1.0_NTREAL DO outer_counter = 1,solver_parameters%max_iterations IF (solver_parameters%be_verbose .AND. outer_counter .GT. 1) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter-1) - CALL EnterSubLog - CALL WriteElement(key="Convergence", VALUE=norm_value) - CALL ExitSubLog + CALL WriteListElement(key="Convergence", VALUE=norm_value) END IF !! x = Ax diff --git a/Source/Fortran/GeometryOptimizationModule.F90 b/Source/Fortran/GeometryOptimizationModule.F90 index 669257f8..a2bb7a8e 100644 --- a/Source/Fortran/GeometryOptimizationModule.F90 +++ b/Source/Fortran/GeometryOptimizationModule.F90 @@ -4,7 +4,7 @@ MODULE GeometryOptimizationModule USE DataTypesModule, ONLY : NTREAL USE LoadBalancerModule, ONLY : PermuteMatrix, UndoPermuteMatrix USE LoggingModule, ONLY : EnterSubLog, ExitSubLog, WriteHeader, & - & WriteElement, WriteListElement, WriteCitation + & WriteElement, WriteListElement USE PMatrixMemoryPoolModule, ONLY : MatrixMemoryPool_p, & & DestructMatrixMemoryPool USE PSMatrixAlgebraModule, ONLY : MatrixMultiply, MatrixNorm, & @@ -59,7 +59,10 @@ SUBROUTINE PurificationExtrapolate(PreviousDensity, Overlap, nel, NewDensity,& CALL WriteHeader("Density Matrix Extrapolator") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="Purification") - CALL WriteCitation("niklasson2010trace") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("niklasson2010trace") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -107,9 +110,8 @@ SUBROUTINE PurificationExtrapolate(PreviousDensity, Overlap, nel, NewDensity,& norm_value = MatrixNorm(WorkingDensity) IF (solver_parameters%be_verbose) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter) + CALL WriteListElement(key="Convergence", VALUE=norm_value) CALL EnterSubLog - CALL WriteElement(key="Convergence", VALUE=norm_value) CALL WriteElement(key="Trace", VALUE=trace_value) CALL ExitSubLog END IF @@ -180,7 +182,10 @@ SUBROUTINE LowdinExtrapolate(PreviousDensity, OldOverlap, NewOverlap, & CALL WriteHeader("Density Matrix Extrapolator") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="Lowdin") - CALL WriteCitation("exner2002comparison") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("exner2002comparison") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF diff --git a/Source/Fortran/InverseSolversModule.F90 b/Source/Fortran/InverseSolversModule.F90 index 0333c56c..b6a19ba8 100644 --- a/Source/Fortran/InverseSolversModule.F90 +++ b/Source/Fortran/InverseSolversModule.F90 @@ -4,7 +4,7 @@ MODULE InverseSolversModule USE DataTypesModule, ONLY : NTREAL USE LoadBalancerModule, ONLY : PermuteMatrix, UndoPermuteMatrix USE LoggingModule, ONLY : EnterSubLog, ExitSubLog, WriteHeader, & - & WriteElement, WriteListElement, WriteCitation + & WriteElement, WriteListElement USE PMatrixMemoryPoolModule, ONLY : MatrixMemoryPool_p, & & DestructMatrixMemoryPool USE PSMatrixAlgebraModule, ONLY : MatrixMultiply, IncrementMatrix, & @@ -50,7 +50,10 @@ SUBROUTINE Invert(Mat, InverseMat, solver_parameters_in) IF (solver_parameters%be_verbose) THEN CALL WriteHeader("Inverse Solver") CALL EnterSubLog - CALL WriteCitation("palser1998canonical") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("palser1998canonical") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -88,10 +91,7 @@ SUBROUTINE Invert(Mat, InverseMat, solver_parameters_in) norm_value = solver_parameters%converge_diff + 1.0_NTREAL DO outer_counter = 1,solver_parameters%max_iterations IF (solver_parameters%be_verbose .AND. outer_counter .GT. 1) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter-1) - CALL EnterSubLog CALL WriteListElement(key="Convergence", VALUE=norm_value) - CALL ExitSubLog END IF CALL MatrixMultiply(InverseMat,BalancedMat,Temp1, & @@ -172,7 +172,10 @@ SUBROUTINE PseudoInverse(Mat, InverseMat, solver_parameters_in) IF (solver_parameters%be_verbose) THEN CALL WriteHeader("Inverse Solver") CALL EnterSubLog - CALL WriteCitation("palser1998canonical") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("palser1998canonical") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -210,10 +213,7 @@ SUBROUTINE PseudoInverse(Mat, InverseMat, solver_parameters_in) norm_value = solver_parameters%converge_diff + 1.0_NTREAL DO outer_counter = 1,solver_parameters%max_iterations IF (solver_parameters%be_verbose .AND. outer_counter .GT. 1) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter-1) - CALL EnterSubLog CALL WriteListElement(key="Convergence", VALUE=norm_value) - CALL ExitSubLog END IF CALL MatrixMultiply(InverseMat,BalancedMat,Temp1, & diff --git a/Source/Fortran/LinearSolversModule.F90 b/Source/Fortran/LinearSolversModule.F90 index 85e5f69f..f6bbd576 100644 --- a/Source/Fortran/LinearSolversModule.F90 +++ b/Source/Fortran/LinearSolversModule.F90 @@ -100,10 +100,7 @@ SUBROUTINE CGSolver(AMat, XMat, BMat, solver_parameters_in) norm_value = solver_parameters%converge_diff + 1.0_NTREAL DO outer_counter = 1,solver_parameters%max_iterations IF (solver_parameters%be_verbose .AND. outer_counter .GT. 1) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter-1) - CALL EnterSubLog CALL WriteListElement(key="Convergence", VALUE=norm_value) - CALL ExitSubLog END IF IF (norm_value .LE. solver_parameters%converge_diff) THEN EXIT diff --git a/Source/Fortran/LoggingModule.F90 b/Source/Fortran/LoggingModule.F90 index 8e1ff6c3..eb166de6 100644 --- a/Source/Fortran/LoggingModule.F90 +++ b/Source/Fortran/LoggingModule.F90 @@ -7,15 +7,17 @@ MODULE LoggingModule !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! INTEGER :: CurrentLevel = 0 LOGICAL :: IsActive = .FALSE. + INTEGER :: UNIT = 6 + LOGICAL :: file_open = .TRUE. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PUBLIC :: ActivateLogger PUBLIC :: DeactivateLogger +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PUBLIC :: EnterSubLog + PUBLIC :: ExitSubLog + PUBLIC :: WriteElement PUBLIC :: WriteHeader PUBLIC :: WriteListElement - PUBLIC :: WriteElement - PUBLIC :: WriteCitation - PUBLIC :: ExitSubLog !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! INTERFACE WriteListElement MODULE PROCEDURE WriteListElement_bool @@ -31,13 +33,42 @@ MODULE LoggingModule END INTERFACE WriteElement CONTAINS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Activate the logger. - SUBROUTINE ActivateLogger + SUBROUTINE ActivateLogger(start_document_in, file_name_in, unit_in) + !> If this is a new document we can write the start document marker. + LOGICAL, INTENT(IN), OPTIONAL :: start_document_in + !> An optional file name for writing to. + CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: file_name_in + !> An optional fortran i/o unit override. + INTEGER, INTENT(IN), OPTIONAL :: unit_in + IsActive = .TRUE. + + IF (PRESENT(unit_in)) THEN + UNIT = unit_in + END IF + + IF (PRESENT(file_name_in)) THEN + IF (.NOT. PRESENT(unit_in)) THEN + UNIT = 14 + END IF + OPEN(unit = UNIT, file = file_name_in) + file_open = .TRUE. + END IF + + IF (PRESENT(start_document_in)) THEN + IF (start_document_in) THEN + WRITE(UNIT, '(A3)') "---" + END IF + END IF END SUBROUTINE ActivateLogger !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Deactivate the logger. SUBROUTINE DeactivateLogger IsActive = .FALSE. + IF (file_open) THEN + CLOSE(UNIT) + END IF + UNIT = 6 END SUBROUTINE DeactivateLogger !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Call this subroutine when you enter into a section with verbose output @@ -57,8 +88,8 @@ SUBROUTINE WriteHeader(header_value) IF (IsActive) THEN CALL WriteIndent - WRITE(*,'(A)',ADVANCE='no') header_value - WRITE(*,'(A1)') ":" + WRITE(UNIT,'(A)',ADVANCE='no') header_value + WRITE(UNIT,'(A1)') ":" END IF END SUBROUTINE WriteHeader !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -72,14 +103,14 @@ SUBROUTINE WriteElement_bool(key, VALUE) IF (IsActive) THEN CALL WriteIndent - WRITE(*,'(A)',ADVANCE='no') key + WRITE(UNIT,'(A)',ADVANCE='no') key IF (VALUE) THEN - WRITE(*,'(A)',ADVANCE='no') ": True" + WRITE(UNIT,'(A)',ADVANCE='no') ": True" ELSE - WRITE(*,'(A)',ADVANCE='no') ": False" + WRITE(UNIT,'(A)',ADVANCE='no') ": False" END IF - WRITE(*,*) + WRITE(UNIT,*) END IF END SUBROUTINE WriteElement_bool !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -93,11 +124,11 @@ SUBROUTINE WriteElement_float(key, VALUE) IF (IsActive) THEN CALL WriteIndent - WRITE(*,'(A)',ADVANCE='no') key - WRITE(*,'(A)',ADVANCE='no') ": " - WRITE(*,'(ES22.14)',ADVANCE='no') VALUE + WRITE(UNIT,'(A)',ADVANCE='no') key + WRITE(UNIT,'(A)',ADVANCE='no') ": " + WRITE(UNIT,'(ES22.14)',ADVANCE='no') VALUE - WRITE(*,*) + WRITE(UNIT,*) END IF END SUBROUTINE WriteElement_float !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -111,11 +142,11 @@ SUBROUTINE WriteElement_int(key, VALUE) IF (IsActive) THEN CALL WriteIndent - WRITE(*,'(A)',ADVANCE='no') key - WRITE(*,'(A)',ADVANCE='no') ": " - WRITE(*,'(I10)',ADVANCE='no') VALUE + WRITE(UNIT,'(A)',ADVANCE='no') key + WRITE(UNIT,'(A)',ADVANCE='no') ": " + WRITE(UNIT,'(I20)',ADVANCE='no') VALUE - WRITE(*,*) + WRITE(UNIT,*) END IF END SUBROUTINE WriteElement_int !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -129,11 +160,11 @@ SUBROUTINE WriteElement_string(key, VALUE) IF (IsActive) THEN CALL WriteIndent - WRITE(*,'(A)',ADVANCE='no') key - WRITE(*,'(A)',ADVANCE='no') ": " - WRITE(*,'(A)',ADVANCE='no') VALUE + WRITE(UNIT,'(A)',ADVANCE='no') key + WRITE(UNIT,'(A)',ADVANCE='no') ": " + WRITE(UNIT,'(A)',ADVANCE='no') VALUE - WRITE(*,*) + WRITE(UNIT,*) END IF END SUBROUTINE WriteElement_string !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -147,15 +178,15 @@ SUBROUTINE WriteListElement_bool(key, VALUE) IF (IsActive) THEN CALL WriteIndent - WRITE(*,'(A)',ADVANCE='no') "- " - WRITE(*,'(A)',ADVANCE='no') key + WRITE(UNIT,'(A)',ADVANCE='no') "- " + WRITE(UNIT,'(A)',ADVANCE='no') key IF (VALUE) THEN - WRITE(*,'(A)',ADVANCE='no') ": True" + WRITE(UNIT,'(A)',ADVANCE='no') ": True" ELSE - WRITE(*,'(A)',ADVANCE='no') ": False" + WRITE(UNIT,'(A)',ADVANCE='no') ": False" END IF - WRITE(*,*) + WRITE(UNIT,*) END IF END SUBROUTINE WriteListElement_bool !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -169,12 +200,12 @@ SUBROUTINE WriteListElement_float(key, VALUE) IF (IsActive) THEN CALL WriteIndent - WRITE(*,'(A)',ADVANCE='no') "- " - WRITE(*,'(A)',ADVANCE='no') key - WRITE(*,'(A)',ADVANCE='no') ": " - WRITE(*,'(ES22.14)',ADVANCE='no') VALUE + WRITE(UNIT,'(A)',ADVANCE='no') "- " + WRITE(UNIT,'(A)',ADVANCE='no') key + WRITE(UNIT,'(A)',ADVANCE='no') ": " + WRITE(UNIT,'(ES22.14)',ADVANCE='no') VALUE - WRITE(*,*) + WRITE(UNIT,*) END IF END SUBROUTINE WriteListElement_float !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -188,12 +219,12 @@ SUBROUTINE WriteListElement_int(key, VALUE) IF (IsActive) THEN CALL WriteIndent - WRITE(*,'(A)',ADVANCE='no') "- " - WRITE(*,'(A)',ADVANCE='no') key - WRITE(*,'(A)',ADVANCE='no') ": " - WRITE(*,'(I10)',ADVANCE='no') VALUE + WRITE(UNIT,'(A)',ADVANCE='no') "- " + WRITE(UNIT,'(A)',ADVANCE='no') key + WRITE(UNIT,'(A)',ADVANCE='no') ": " + WRITE(UNIT,'(I10)',ADVANCE='no') VALUE - WRITE(*,*) + WRITE(UNIT,*) END IF END SUBROUTINE WriteListElement_int !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -202,52 +233,28 @@ SUBROUTINE WriteListElement_string(key, VALUE) !> Some text to write. CHARACTER(LEN=*), INTENT(IN) :: key !> A text value to write. - CHARACTER(LEN=*), INTENT(IN) :: VALUE + CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: VALUE IF (IsActive) THEN CALL WriteIndent - WRITE(*,'(A)',ADVANCE='no') "- " - WRITE(*,'(A)',ADVANCE='no') key - WRITE(*,'(A)',ADVANCE='no') ": " - WRITE(*,'(A)',ADVANCE='no') VALUE + WRITE(UNIT,'(A)',ADVANCE='no') "- " + WRITE(UNIT,'(A)',ADVANCE='no') key + IF (PRESENT(VALUE)) THEN + WRITE(UNIT,'(A)',ADVANCE='no') ": " + WRITE(UNIT,'(A)',ADVANCE='no') VALUE + END IF - WRITE(*,*) + WRITE(UNIT,*) END IF END SUBROUTINE WriteListElement_string -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !> Write out a citation element. - SUBROUTINE WriteCitation(citation_list) - !> A list of citations, separated by a space. - CHARACTER(LEN=*), INTENT(IN) :: citation_list - INTEGER :: pos1, pos2 - - IF (IsActive) THEN - CALL WriteIndent - WRITE(*,'(A)') "Citations:" - CALL EnterSubLog - - pos1 = 1 - pos2 = INDEX(citation_list(pos1:), ' ') - DO WHILE(pos2 .NE. 0) - CALL WriteIndent - WRITE(*,'(A)') citation_list(pos1:pos1+pos2-1) - pos1 = pos1 + pos2 - pos2 = INDEX(citation_list(pos1:), ' ') - END DO - CALL WriteIndent - WRITE(*,'(A)') citation_list(pos1:) - - CALL ExitSubLog - END IF - END SUBROUTINE WriteCitation !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Writes out the indentation needed for this level SUBROUTINE WriteIndent INTEGER :: counter DO counter=1,CurrentLevel*2 - WRITE(*,'(A1)',ADVANCE='NO') " " + WRITE(UNIT,'(A1)',ADVANCE='NO') " " END DO END SUBROUTINE WriteIndent !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/Source/Fortran/PolynomialSolversModule.F90 b/Source/Fortran/PolynomialSolversModule.F90 index 9fdaf581..58b7cd22 100644 --- a/Source/Fortran/PolynomialSolversModule.F90 +++ b/Source/Fortran/PolynomialSolversModule.F90 @@ -4,7 +4,7 @@ MODULE PolynomialSolversModule USE DataTypesModule, ONLY : NTREAL USE LoadBalancerModule, ONLY : PermuteMatrix, UndoPermuteMatrix USE LoggingModule, ONLY : EnterSubLog, ExitSubLog, WriteElement, & - & WriteCitation, WriteHeader + & WriteListElement, WriteHeader USE PMatrixMemoryPoolModule, ONLY : MatrixMemoryPool_p, & & DestructMatrixMemoryPool USE PSMatrixAlgebraModule, ONLY : IncrementMatrix, MatrixMultiply, & @@ -206,7 +206,10 @@ SUBROUTINE FactorizedCompute_stand(InputMat, OutputMat, poly, & CALL WriteHeader("Polynomial Solver") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="Paterson Stockmeyer") - CALL WriteCitation("paterson1973number") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("paterson1973number") + CALL ExitSubLog CALL PrintParameters(solver_parameters) CALL WriteElement(key="Degree", VALUE=degree-1) END IF diff --git a/Source/Fortran/ProcessGridModule.F90 b/Source/Fortran/ProcessGridModule.F90 index 915229da..1d25f2a0 100644 --- a/Source/Fortran/ProcessGridModule.F90 +++ b/Source/Fortran/ProcessGridModule.F90 @@ -2,7 +2,7 @@ !> A module to manage the process grid. MODULE ProcessGridModule USE ErrorModule, ONLY : Error_t, ConstructError, SetGenericError - USE LoggingModule, ONLY : ActivateLogger, EnterSubLog, ExitSubLog, & + USE LoggingModule, ONLY : EnterSubLog, ExitSubLog, & & WriteHeader, WriteListElement USE NTMPIModule #ifdef _OPENMP @@ -103,9 +103,6 @@ SUBROUTINE ConstructProcessGrid_full(world_comm_, process_rows_, & & process_columns_, process_slices_) !! Report - IF (IsRoot(global_grid)) THEN - CALL ActivateLogger - END IF IF (be_verbose) THEN CALL WriteHeader("Process Grid") CALL EnterSubLog @@ -547,16 +544,17 @@ SUBROUTINE SplitProcessGrid(old_grid, new_grid, my_color, split_slice, & END SUBROUTINE SplitProcessGrid !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Check if the current process is the root process. - FUNCTION IsRoot(grid) RESULT(is_root) + FUNCTION IsRoot(grid_in) RESULT(is_root) !! Parameters !> The process grid. - TYPE(ProcessGrid_t), INTENT(IN) :: grid + TYPE(ProcessGrid_t), INTENT(IN), OPTIONAL :: grid_in !> True if the current process is root. LOGICAL :: is_root - IF (grid%global_rank == 0) THEN - is_root = .TRUE. + + IF (PRESENT(grid_in)) THEN + is_root = (grid_in%global_rank .EQ. 0) ELSE - is_root = .FALSE. + is_root = (global_grid%global_rank .EQ. 0) END IF END FUNCTION IsRoot !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/Source/Fortran/RootSolversModule.F90 b/Source/Fortran/RootSolversModule.F90 index 5846238f..cc6eefd4 100644 --- a/Source/Fortran/RootSolversModule.F90 +++ b/Source/Fortran/RootSolversModule.F90 @@ -6,7 +6,7 @@ MODULE RootSolversModule USE InverseSolversModule, ONLY : Invert USE LoadBalancerModule, ONLY : PermuteMatrix, UndoPermuteMatrix USE LoggingModule, ONLY : EnterSubLog, ExitSubLog, WriteListElement, & - & WriteHeader, WriteElement, WriteCitation + & WriteHeader, WriteElement USE PolynomialSolversModule, ONLY : Polynomial_t, ConstructPolynomial, & & DestructPolynomial, FactorizedCompute, SetCoefficient USE PMatrixMemoryPoolModule, ONLY : MatrixMemoryPool_p, & @@ -229,7 +229,10 @@ SUBROUTINE ComputeInverseRootImplemention(InputMat, OutputMat, root, & IF (solver_parameters_in%be_verbose) THEN CALL WriteHeader("Root Solver") CALL EnterSubLog - CALL WriteCitation("nicholas2008functions") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("nicholas2008functions") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -285,10 +288,7 @@ SUBROUTINE ComputeInverseRootImplemention(InputMat, OutputMat, root, & norm_value = solver_parameters%converge_diff + 1.0_NTREAL DO outer_counter = 1,solver_parameters%max_iterations IF (solver_parameters%be_verbose .AND. outer_counter .GT. 1) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter-1) - CALL EnterSubLog - CALL WriteElement(key="Convergence", VALUE=norm_value) - CALL ExitSubLog + CALL WriteListElement(key="Convergence", VALUE=norm_value) END IF CALL CopyMatrix(IdentityMat, IntermediateMat) diff --git a/Source/Fortran/SignSolversModule.F90 b/Source/Fortran/SignSolversModule.F90 index 21010548..b5a8e4ad 100644 --- a/Source/Fortran/SignSolversModule.F90 +++ b/Source/Fortran/SignSolversModule.F90 @@ -5,7 +5,7 @@ MODULE SignSolversModule USE EigenBoundsModule, ONLY : GershgorinBounds USE LoadBalancerModule, ONLY : PermuteMatrix, UndoPermuteMatrix USE LoggingModule, ONLY : EnterSubLog, ExitSubLog, WriteHeader, & - & WriteListElement, WriteElement, WriteCitation + & WriteListElement, WriteElement USE PMatrixMemoryPoolModule, ONLY : MatrixMemoryPool_p, & & DestructMatrixMemoryPool USE PSMatrixAlgebraModule, ONLY : MatrixMultiply, IncrementMatrix, & @@ -42,7 +42,10 @@ SUBROUTINE SignFunction(Mat, SignMat, solver_parameters_in) IF (solver_parameters%be_verbose) THEN CALL WriteHeader("Sign Function Solver") CALL EnterSubLog - CALL WriteCitation("nicholas2008functions") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("nicholas2008functions") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -80,7 +83,10 @@ SUBROUTINE PolarDecomposition(Mat, Umat, Hmat, solver_parameters_in) IF (solver_parameters%be_verbose) THEN CALL WriteHeader("Polar Decomposition Solver") CALL EnterSubLog - CALL WriteCitation("nicholas2008functions") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("nicholas2008functions") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -160,10 +166,7 @@ SUBROUTINE CoreComputation(Mat, OutMat, solver_parameters, needs_transpose) norm_value = solver_parameters%converge_diff + 1.0_NTREAL iterate: DO outer_counter = 1,solver_parameters%max_iterations IF (solver_parameters%be_verbose .AND. outer_counter .GT. 1) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter-1) - CALL EnterSubLog - CALL WriteElement(key="Convergence", VALUE=norm_value) - CALL ExitSubLog + CALL WriteListElement(key="Convergence", VALUE=norm_value) END IF !! Update Scaling Factors diff --git a/Source/Fortran/SquareRootSolversModule.F90 b/Source/Fortran/SquareRootSolversModule.F90 index 969afe28..75bf816a 100644 --- a/Source/Fortran/SquareRootSolversModule.F90 +++ b/Source/Fortran/SquareRootSolversModule.F90 @@ -5,7 +5,7 @@ MODULE SquareRootSolversModule USE EigenBoundsModule, ONLY : GershgorinBounds USE LoadBalancerModule, ONLY : PermuteMatrix, UndoPermuteMatrix USE LoggingModule, ONLY : EnterSubLog, ExitSubLog, WriteListElement, & - & WriteHeader, WriteElement, WriteCitation + & WriteHeader, WriteElement USE PMatrixMemoryPoolModule, ONLY : MatrixMemoryPool_p, & & DestructMatrixMemoryPool USE PSMatrixAlgebraModule, ONLY : MatrixMultiply, MatrixNorm, & @@ -144,7 +144,10 @@ SUBROUTINE NewtonSchultzISROrder2(Mat, OutMat, solver_parameters, & IF (solver_parameters%be_verbose) THEN CALL WriteHeader("Newton Schultz Inverse Square Root") CALL EnterSubLog - CALL WriteCitation("jansik2007linear") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("jansik2007linear") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -217,10 +220,7 @@ SUBROUTINE NewtonSchultzISROrder2(Mat, OutMat, solver_parameters, & CALL ScaleMatrix(SquareRootMat,SQRT(lambda)) IF (solver_parameters%be_verbose) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter) - CALL EnterSubLog CALL WriteElement(key="Convergence", VALUE=norm_value) - CALL ExitSubLog END IF IF (norm_value .LE. solver_parameters%converge_diff) THEN @@ -289,7 +289,10 @@ SUBROUTINE NewtonSchultzISRTaylor(Mat, OutMat, solver_parameters, & IF (solver_parameters%be_verbose) THEN CALL WriteHeader("Newton Schultz Inverse Square Root") CALL EnterSubLog - CALL WriteCitation("jansik2007linear") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("jansik2007linear") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -402,10 +405,7 @@ SUBROUTINE NewtonSchultzISRTaylor(Mat, OutMat, solver_parameters, & & threshold_in=solver_parameters%threshold,memory_pool_in=mpool) IF (solver_parameters%be_verbose) THEN - CALL WriteListElement(key="Round", VALUE=outer_counter) - CALL EnterSubLog - CALL WriteElement(key="Convergence", VALUE=norm_value) - CALL ExitSubLog + CALL WriteListElement(key="Convergence", VALUE=norm_value) END IF IF (norm_value .LE. solver_parameters%converge_diff) THEN diff --git a/Source/Fortran/TrigonometrySolversModule.F90 b/Source/Fortran/TrigonometrySolversModule.F90 index 1c318c14..9670a998 100644 --- a/Source/Fortran/TrigonometrySolversModule.F90 +++ b/Source/Fortran/TrigonometrySolversModule.F90 @@ -5,7 +5,7 @@ MODULE TrigonometrySolversModule USE EigenBoundsModule, ONLY : GershgorinBounds USE LoadBalancerModule, ONLY : PermuteMatrix, UndoPermuteMatrix USE LoggingModule, ONLY : EnterSubLog, ExitSubLog, WriteHeader, & - & WriteElement, WriteCitation + & WriteListElement, WriteElement USE PMatrixMemoryPoolModule, ONLY : MatrixMemoryPool_p, & & DestructMatrixMemoryPool USE PSMatrixAlgebraModule, ONLY : MatrixMultiply, IncrementMatrix, & @@ -104,7 +104,10 @@ SUBROUTINE ScaleSquareTrigonometryTaylor(InputMat, OutputMat, & CALL WriteHeader("Trigonometry Solver") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="Taylor") - CALL WriteCitation("higham2003computing") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("higham2003computing") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF @@ -221,8 +224,12 @@ SUBROUTINE ScaleSquareTrigonometry(InputMat, OutputMat, solver_parameters_in) CALL WriteHeader("Trigonometry Solver") CALL EnterSubLog CALL WriteElement(key="Method", VALUE="Chebyshev") - CALL WriteCitation("serbin1980algorithm higham2003computing& - & yau1993reducing") + CALL WriteHeader("Citations") + CALL EnterSubLog + CALL WriteListElement("serbin1980algorithm") + CALL WriteListElement("higham2003computing") + CALL WriteListElement("yau1993reducing") + CALL ExitSubLog CALL PrintParameters(solver_parameters) END IF diff --git a/Source/Swig/NTPolySwig.i b/Source/Swig/NTPolySwig.i index 85731b18..939a2b18 100644 --- a/Source/Swig/NTPolySwig.i +++ b/Source/Swig/NTPolySwig.i @@ -18,6 +18,7 @@ #include "InverseSolvers.h" #include "LinearSolvers.h" #include "LoadBalancer.h" +#include "Logging.h" #include "MatrixConversion.h" #include "MatrixMapper.h" #include "MatrixMemoryPool.h" @@ -54,6 +55,7 @@ using namespace NTPoly; %include "InverseSolvers.h" %include "LinearSolvers.h" %include "LoadBalancer.h" +%include "Logging.h" %include "MatrixConversion.h" %include "MatrixMapper.h" %include "MatrixMemoryPool.h" diff --git a/Source/Wrapper/CMakeLists.txt b/Source/Wrapper/CMakeLists.txt index 4dfd5039..4388bcc0 100644 --- a/Source/Wrapper/CMakeLists.txt +++ b/Source/Wrapper/CMakeLists.txt @@ -9,6 +9,7 @@ set(Wsrc InverseSolversModule_wrp.F90 LinearSolversModule_wrp.F90 LoadBalancerModule_wrp.F90 + LoggingModule_wrp.F90 MatrixConversionModule_wrp.F90 MatrixMemoryPoolModule_wrp.F90 PermutationModule_wrp.F90 diff --git a/Source/Wrapper/LoggingModule_wrp.F90 b/Source/Wrapper/LoggingModule_wrp.F90 new file mode 100644 index 00000000..d2af09db --- /dev/null +++ b/Source/Wrapper/LoggingModule_wrp.F90 @@ -0,0 +1,42 @@ +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!> A module for writing data to the log file. +MODULE LoggingModule_wrp + USE LoggingModule + USE ISO_C_BINDING, ONLY : c_char, c_int, c_bool + IMPLICIT NONE + PRIVATE +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + PUBLIC :: ActivateLogger_wrp + PUBLIC :: ActivateLoggerFile_wrp + PUBLIC :: DeactivateLogger_wrp +CONTAINS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Activate the logger and have it write to a file. + SUBROUTINE ActivateLoggerFile_wrp(start_document, file_name, name_size) & + & BIND(C,NAME="ActivateLoggerFile_wrp") + LOGICAL(KIND=C_BOOL) :: start_document + CHARACTER(KIND=C_CHAR), INTENT(IN) :: file_name(name_size) + INTEGER(KIND=C_INT), INTENT(IN) :: name_size + !! Local Data + CHARACTER(LEN=name_size) :: local_string + INTEGER :: II + + DO II=1,name_size + local_string(II:II) = file_name(II) + END DO + + CALL ActivateLogger(LOGICAL(start_document), local_string) + END SUBROUTINE ActivateLoggerFile_wrp +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Activate the logger. + SUBROUTINE ActivateLogger_wrp(start_document) & + & BIND(C,NAME="ActivateLogger_wrp") + LOGICAL(KIND=C_BOOL) :: start_document + CALL ActivateLogger(LOGICAL(start_document)) + END SUBROUTINE ActivateLogger_wrp +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Activate the logger. + SUBROUTINE DeactivateLogger_wrp() BIND(C,NAME="DeactivateLogger_wrp") + CALL DeactivateLogger() + END SUBROUTINE DeactivateLogger_wrp +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +END MODULE LoggingModule_wrp diff --git a/Source/Wrapper/ProcessGridModule_wrp.F90 b/Source/Wrapper/ProcessGridModule_wrp.F90 index c25dee74..24487242 100644 --- a/Source/Wrapper/ProcessGridModule_wrp.F90 +++ b/Source/Wrapper/ProcessGridModule_wrp.F90 @@ -1,9 +1,7 @@ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> A wrapper for the process grid module. MODULE ProcessGridModule_wrp - USE ProcessGridModule, ONLY : ConstructProcessGrid, DestructProcessGrid, & - & GetMySlice, GetMyColumn, GetMyRow, global_grid, ProcessGrid_t, & - & ConstructNewProcessGrid, CopyProcessGrid + USE ProcessGridModule USE WrapperModule, ONLY : SIZE_wrp USE ISO_C_BINDING, ONLY : c_int, c_bool IMPLICIT NONE @@ -20,6 +18,7 @@ MODULE ProcessGridModule_wrp PUBLIC :: GetGlobalMySlice_wrp PUBLIC :: GetGlobalMyColumn_wrp PUBLIC :: GetGlobalMyRow_wrp + PUBLIC :: GetGlobalIsRoot_wrp PUBLIC :: GetGlobalNumSlices_wrp PUBLIC :: GetGlobalNumColumns_wrp PUBLIC :: GetGlobalNumRows_wrp @@ -90,6 +89,13 @@ FUNCTION GetGlobalMyRow_wrp() RESULT(return_val) & INTEGER(kind=c_int) :: return_val return_val = GetMyRow() END FUNCTION GetGlobalMyRow_wrp +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !> Get if the current process is root. + FUNCTION GetGlobalIsRoot_wrp() RESULT(return_val) & + & BIND(c,name="GetGlobalIsRoot_wrp") + LOGICAL(kind=c_bool) :: return_val + return_val = LOGICAL(IsRoot(),KIND=c_bool) + END FUNCTION GetGlobalIsRoot_wrp !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !> Get the number of process slices. FUNCTION GetGlobalNumSlices_wrp() RESULT(return_val) & diff --git a/UnitTests/before_install.sh b/UnitTests/before_install.sh index 7d08a07d..1b4437d4 100644 --- a/UnitTests/before_install.sh +++ b/UnitTests/before_install.sh @@ -26,6 +26,7 @@ if [[ "$TESTOS" == "OSX" ]]; then sudo pip2 install scipy --upgrade --no-cache-dir sudo pip2 install mpi4py --upgrade --no-cache-dir sudo pip2 install flake8 --upgrade --no-cache-dir + sudo pip2 install pyyaml --upgrade --no-cache-dir else sudo ldconfig sudo apt-get install python-dev python-pip python-all-dev @@ -35,6 +36,7 @@ else sudo pip install scipy --upgrade sudo pip install mpi4py --upgrade sudo pip install flake8 --upgrade + sudo pip install pyyaml --upgrade fi test -n $CC && unset CC diff --git a/UnitTests/helpers.py b/UnitTests/helpers.py index 6666ac99..bbe3236d 100644 --- a/UnitTests/helpers.py +++ b/UnitTests/helpers.py @@ -7,6 +7,8 @@ scratch_dir = environ['SCRATCHDIR'] # Filename to use for results. result_file = join(scratch_dir, "result.mtx") +# Logfile for testing the logger +log_file = join(scratch_dir, "log.yaml") # Threshold value for comparing floating point values. THRESHOLD = 1e-4 # Threshold used for checking extrapolazation. diff --git a/UnitTests/test_chemistry.py b/UnitTests/test_chemistry.py index b70a3320..cc77e819 100644 --- a/UnitTests/test_chemistry.py +++ b/UnitTests/test_chemistry.py @@ -83,11 +83,21 @@ def tearDownClass(self): '''Cleanup this test''' nt.DestructGlobalProcessGrid() + def tearDown(self): + from helpers import log_file + from yaml import load, dump + from sys import stdout + if nt.GetGlobalIsRoot(): + nt.DeactivateLogger() + with open(log_file) as ifile: + data = load(ifile) + dump(data, stdout) + def setUp(self): '''Set up an individual test.''' from os import environ from os.path import join - from helpers import scratch_dir + from helpers import scratch_dir, log_file self.my_rank = comm.Get_rank() self.solver_parameters = nt.SolverParameters() @@ -104,6 +114,9 @@ def setUp(self): self.density = join(scratch_dir, "rd.mtx") self.mat_dim = 7 + if nt.GetGlobalIsRoot(): + nt.ActivateLogger(log_file, True) + def check_full(self): '''Compare two computed matrices.''' from helpers import THRESHOLD, result_file diff --git a/UnitTests/test_solvers.py b/UnitTests/test_solvers.py index 88b27b78..86d06125 100644 --- a/UnitTests/test_solvers.py +++ b/UnitTests/test_solvers.py @@ -7,7 +7,7 @@ from scipy.sparse import csr_matrix from scipy.io import mmread from mpi4py import MPI -from helpers import result_file +from helpers import result_file, log_file # MPI global communicator. @@ -45,6 +45,28 @@ def tearDownClass(self): '''Cleanup this test''' nt.DestructGlobalProcessGrid() + def setUp(self): + '''Set up all of the tests.''' + # Rank of the current process. + self.my_rank = comm.Get_rank() + # Parameters for iterative solvers. + self.isp = nt.SolverParameters() + # Parameters for fixed solvers. + self.fsp = nt.SolverParameters() + self.fsp.SetVerbosity(True) + self.isp.SetVerbosity(True) + if nt.GetGlobalIsRoot(): + nt.ActivateLogger(log_file, True) + + def tearDown(self): + from yaml import load, dump + from sys import stdout + if nt.GetGlobalIsRoot(): + nt.DeactivateLogger() + with open(log_file) as ifile: + data = load(ifile) + dump(data, stdout) + def create_matrix(self, SPD=None, scaled=None, diag_dom=None, rank=None): ''' Create the test matrix with the following parameters. @@ -70,17 +92,6 @@ def write_matrix(self, mat, file_name): mmwrite(file_name, csr_matrix(mat)) comm.barrier() - def setUp(self): - '''Set up all of the tests.''' - # Rank of the current process. - self.my_rank = comm.Get_rank() - # Parameters for iterative solvers. - self.isp = nt.SolverParameters() - # Parameters for fixed solvers. - self.fsp = nt.SolverParameters() - self.fsp.SetVerbosity(True) - self.isp.SetVerbosity(True) - def check_result(self): '''Compare two computed matrices.''' from helpers import THRESHOLD