From 95d52e5b4ad08a6becc180f8814874bd93f7bba2 Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Sat, 17 Feb 2018 23:18:39 +0100 Subject: [PATCH] scalapack: split _06 test into four --- tests/scalapack/scalapack_06.cc | 96 ++++------- tests/scalapack/scalapack_06.mpirun=1.output | 30 ---- tests/scalapack/scalapack_06.mpirun=11.output | 30 ---- tests/scalapack/scalapack_06.mpirun=4.output | 30 ---- tests/scalapack/scalapack_06.mpirun=9.output | 30 ---- tests/scalapack/scalapack_06a.cc | 119 +++++++++++++ tests/scalapack/scalapack_06a.mpirun=1.output | 18 ++ .../scalapack/scalapack_06a.mpirun=11.output | 18 ++ tests/scalapack/scalapack_06a.mpirun=4.output | 18 ++ tests/scalapack/scalapack_06a.mpirun=9.output | 18 ++ tests/scalapack/scalapack_06b.cc | 156 ++++++++++++++++++ tests/scalapack/scalapack_06b.mpirun=1.output | 30 ++++ .../scalapack/scalapack_06b.mpirun=11.output | 30 ++++ tests/scalapack/scalapack_06b.mpirun=4.output | 30 ++++ tests/scalapack/scalapack_06b.mpirun=9.output | 30 ++++ tests/scalapack/scalapack_06c.cc | 127 ++++++++++++++ tests/scalapack/scalapack_06c.mpirun=1.output | 18 ++ .../scalapack/scalapack_06c.mpirun=11.output | 18 ++ tests/scalapack/scalapack_06c.mpirun=4.output | 18 ++ tests/scalapack/scalapack_06c.mpirun=9.output | 18 ++ 20 files changed, 695 insertions(+), 187 deletions(-) create mode 100644 tests/scalapack/scalapack_06a.cc create mode 100644 tests/scalapack/scalapack_06a.mpirun=1.output create mode 100644 tests/scalapack/scalapack_06a.mpirun=11.output create mode 100644 tests/scalapack/scalapack_06a.mpirun=4.output create mode 100644 tests/scalapack/scalapack_06a.mpirun=9.output create mode 100644 tests/scalapack/scalapack_06b.cc create mode 100644 tests/scalapack/scalapack_06b.mpirun=1.output create mode 100644 tests/scalapack/scalapack_06b.mpirun=11.output create mode 100644 tests/scalapack/scalapack_06b.mpirun=4.output create mode 100644 tests/scalapack/scalapack_06b.mpirun=9.output create mode 100644 tests/scalapack/scalapack_06c.cc create mode 100644 tests/scalapack/scalapack_06c.mpirun=1.output create mode 100644 tests/scalapack/scalapack_06c.mpirun=11.output create mode 100644 tests/scalapack/scalapack_06c.mpirun=4.output create mode 100644 tests/scalapack/scalapack_06c.mpirun=9.output diff --git a/tests/scalapack/scalapack_06.cc b/tests/scalapack/scalapack_06.cc index 461ae55d86..28fcef2224 100644 --- a/tests/scalapack/scalapack_06.cc +++ b/tests/scalapack/scalapack_06.cc @@ -17,6 +17,7 @@ #include "../lapack/create_matrix.h" // test eigenpairs_symmetric_by_index(const std::pair &, const bool) +// for all eigenvalues with eigenvectors #include #include @@ -49,18 +50,29 @@ void test(const unsigned int size, const unsigned int block_size, const NumberTy pcout << size << " " << block_size << " " << grid->get_process_grid_rows() << " " << grid->get_process_grid_columns() << std::endl; + const unsigned int n_eigenvalues = size; + const unsigned int max_n_eigenvalues = 5; + // Create SPD matrices of requested size: FullMatrix full_A(size); - std::vector lapack_A(size*size); + std::vector eigenvalues_Lapack(size); + std::vector> s_eigenvectors_ (max_n_eigenvalues,Vector(size)); + std::vector> p_eigenvectors_ (max_n_eigenvalues,Vector(size)); + FullMatrix p_eigenvectors (size,size); + + ScaLAPACKMatrix scalapack_syev (size, grid, block_size); + scalapack_syev.set_property(LAPACKSupport::Property::symmetric); create_spd (full_A); - for (unsigned int i = 0; i < size; ++i) - for (unsigned int j = 0; j < size; ++j) - lapack_A[i*size+j] = full_A(i,j); + scalapack_syev = full_A; - std::vector eigenvalues_Lapack(size); //Lapack as reference { + std::vector lapack_A(size*size); + for (unsigned int i = 0; i < size; ++i) + for (unsigned int j = 0; j < size; ++j) + lapack_A[i*size+j] = full_A(i,j); + int info; //Variable containing information about the successfull exit of the lapack routine char jobz = 'V'; //'V': all eigenpairs of A are computed char uplo = 'U'; //storage format of the matrix A; not so important as matrix is symmetric @@ -77,86 +89,36 @@ void test(const unsigned int size, const unsigned int block_size, const NumberTy syev(&jobz, &uplo, &LDA, & *lapack_A.begin(), &LDA, & *eigenvalues_Lapack.begin(), & *work.begin(), &lwork, &info); AssertThrow (info==0, LAPACKSupport::ExcErrorCode("syev", info)); + for (int i=0; i> s_eigenvectors_ (max_n_eigenvalues,Vector(size)); - for (int i=0; i eigenvalues_psyev; - ScaLAPACKMatrix scalapack_syev (size, grid, block_size); - scalapack_syev.set_property(LAPACKSupport::Property::symmetric); - scalapack_syev = full_A; - eigenvalues_psyev = scalapack_syev.eigenpairs_symmetric_by_index(std::make_pair(0,size-1),true); - FullMatrix p_eigenvectors (size,size); + const std::vector eigenvalues_psyev = scalapack_syev.eigenpairs_symmetric_by_index(std::make_pair(0,size-1),true); scalapack_syev.copy_to(p_eigenvectors); for (unsigned int i=0; i> p_eigenvectors_ (max_n_eigenvalues,Vector(size)); - for (unsigned int i=0; i eigenvalues_psyevx_partial; - ScaLAPACKMatrix scalapack_syevx_partial (size, grid, block_size); - scalapack_syevx_partial.set_property(LAPACKSupport::Property::symmetric); - scalapack_syevx_partial = full_A; - eigenvalues_psyevx_partial = scalapack_syevx_partial.eigenpairs_symmetric_by_index(std::make_pair(size-max_n_eigenvalues,size-1),true); - scalapack_syevx_partial.copy_to(p_eigenvectors); - for (unsigned int i=eigenvalues_psyevx_partial.size()-1; i>0; --i) - { - if ( !(std::abs(eigenvalues_psyevx_partial[i]-eigenvalues_Lapack[size-eigenvalues_psyevx_partial.size()+i]) / - std::abs(eigenvalues_Lapack[size-eigenvalues_psyevx_partial.size()+i]) < tol)) - { - std::cout << "process #" << this_mpi_process << ": eigenvalues do not fit: " - << eigenvalues_psyevx_partial[i] << " <--> " << eigenvalues_Lapack[size-eigenvalues_psyevx_partial.size()+i] << std::endl; - } - - AssertThrow ( std::abs(eigenvalues_psyevx_partial[i]-eigenvalues_Lapack[size-eigenvalues_psyevx_partial.size()+i]) / - std::abs(eigenvalues_Lapack[size-eigenvalues_psyevx_partial.size()+i]) < tol, - dealii::ExcInternalError()); - } pcout << " with respect to the given tolerance the eigenvalues coincide" << std::endl; for (unsigned int i=0; i &, const bool) +// for all eigenvalues without eigenvectors + + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + + +template +void test(const unsigned int size, const unsigned int block_size, const NumberType tol) +{ + MPI_Comm mpi_communicator(MPI_COMM_WORLD); + const unsigned int n_mpi_processes(Utilities::MPI::n_mpi_processes(mpi_communicator)); + const unsigned int this_mpi_process(Utilities::MPI::this_mpi_process(mpi_communicator)); + + ConditionalOStream pcout (std::cout, (this_mpi_process ==0)); + + std::shared_ptr grid = std::make_shared(mpi_communicator,size,size,block_size,block_size); + + pcout << size << " " << block_size << " " << grid->get_process_grid_rows() << " " << grid->get_process_grid_columns() << std::endl; + + const unsigned int n_eigenvalues = size; + const unsigned int max_n_eigenvalues = 5; + + // Create SPD matrices of requested size: + FullMatrix full_A(size); + std::vector eigenvalues_Lapack(size); + + ScaLAPACKMatrix scalapack_syev (size, grid, block_size); + scalapack_syev.set_property(LAPACKSupport::Property::symmetric); + + create_spd (full_A); + scalapack_syev = full_A; + + //Lapack as reference + { + std::vector lapack_A(size*size); + for (unsigned int i = 0; i < size; ++i) + for (unsigned int j = 0; j < size; ++j) + lapack_A[i*size+j] = full_A(i,j); + + int info; //Variable containing information about the successfull exit of the lapack routine + char jobz = 'V'; //'V': all eigenpairs of A are computed + char uplo = 'U'; //storage format of the matrix A; not so important as matrix is symmetric + int LDA = size; //leading dimension of the matrix A + int lwork; //length of vector/array work + std::vector work (1); + + //by setting lwork to -1 a workspace query for work is done + //as matrix is symmetric: LDA == size of matrix + lwork = -1; + syev(&jobz, &uplo, &LDA, & *lapack_A.begin(), &LDA, & *eigenvalues_Lapack.begin(), & *work.begin(), &lwork, &info); + lwork=work[0]; + work.resize (lwork); + syev(&jobz, &uplo, &LDA, & *lapack_A.begin(), &LDA, & *eigenvalues_Lapack.begin(), & *work.begin(), &lwork, &info); + + AssertThrow (info==0, LAPACKSupport::ExcErrorCode("syev", info)); + } + + // the actual test: + + pcout << "comparing " << max_n_eigenvalues << " eigenvalues computed using LAPACK and ScaLAPACK pdsyev:" << std::endl; + const std::vector eigenvalues_psyev = scalapack_syev.eigenpairs_symmetric_by_index(std::make_pair(0,size-1),false); + for (unsigned int i=0; i sizes = {{200,400,600}}; + const std::vector blocks = {{32,64}}; + + const double tol = 1e-10; + + for (const auto &s : sizes) + for (const auto &b : blocks) + if (b <= s) + test(s,b,tol); +} diff --git a/tests/scalapack/scalapack_06a.mpirun=1.output b/tests/scalapack/scalapack_06a.mpirun=1.output new file mode 100644 index 0000000000..07c225df72 --- /dev/null +++ b/tests/scalapack/scalapack_06a.mpirun=1.output @@ -0,0 +1,18 @@ +200 32 1 1 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +200 64 1 1 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +400 32 1 1 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +400 64 1 1 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +600 32 1 1 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +600 64 1 1 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide diff --git a/tests/scalapack/scalapack_06a.mpirun=11.output b/tests/scalapack/scalapack_06a.mpirun=11.output new file mode 100644 index 0000000000..aa55a5f0ce --- /dev/null +++ b/tests/scalapack/scalapack_06a.mpirun=11.output @@ -0,0 +1,18 @@ +200 32 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +200 64 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +400 32 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +400 64 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +600 32 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +600 64 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide diff --git a/tests/scalapack/scalapack_06a.mpirun=4.output b/tests/scalapack/scalapack_06a.mpirun=4.output new file mode 100644 index 0000000000..8b3571e6f7 --- /dev/null +++ b/tests/scalapack/scalapack_06a.mpirun=4.output @@ -0,0 +1,18 @@ +200 32 2 2 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +200 64 2 2 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +400 32 2 2 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +400 64 2 2 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +600 32 2 2 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +600 64 2 2 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide diff --git a/tests/scalapack/scalapack_06a.mpirun=9.output b/tests/scalapack/scalapack_06a.mpirun=9.output new file mode 100644 index 0000000000..aa55a5f0ce --- /dev/null +++ b/tests/scalapack/scalapack_06a.mpirun=9.output @@ -0,0 +1,18 @@ +200 32 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +200 64 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +400 32 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +400 64 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +600 32 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide +600 64 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyev: + with respect to the given tolerance the eigenvalues coincide diff --git a/tests/scalapack/scalapack_06b.cc b/tests/scalapack/scalapack_06b.cc new file mode 100644 index 0000000000..98591a2e92 --- /dev/null +++ b/tests/scalapack/scalapack_06b.cc @@ -0,0 +1,156 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 - 2018 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +#include "../tests.h" +#include "../lapack/create_matrix.h" + +// test eigenpairs_symmetric_by_index(const std::pair &, const bool) +// for some eigenvalues with eigenvectors + + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + + +template +void test(const unsigned int size, const unsigned int block_size, const NumberType tol) +{ + MPI_Comm mpi_communicator(MPI_COMM_WORLD); + const unsigned int n_mpi_processes(Utilities::MPI::n_mpi_processes(mpi_communicator)); + const unsigned int this_mpi_process(Utilities::MPI::this_mpi_process(mpi_communicator)); + + ConditionalOStream pcout (std::cout, (this_mpi_process ==0)); + + std::shared_ptr grid = std::make_shared(mpi_communicator,size,size,block_size,block_size); + + pcout << size << " " << block_size << " " << grid->get_process_grid_rows() << " " << grid->get_process_grid_columns() << std::endl; + + const unsigned int n_eigenvalues = size; + const unsigned int max_n_eigenvalues = 5; + + // Create SPD matrices of requested size: + FullMatrix full_A(size); + std::vector eigenvalues_Lapack(size); + std::vector> s_eigenvectors_ (max_n_eigenvalues,Vector(size)); + std::vector> p_eigenvectors_ (max_n_eigenvalues,Vector(size)); + FullMatrix p_eigenvectors (size,size); + + ScaLAPACKMatrix scalapack_syevx (size, grid, block_size); + scalapack_syevx.set_property(LAPACKSupport::Property::symmetric); + + create_spd (full_A); + scalapack_syevx = full_A; + + //Lapack as reference + { + std::vector lapack_A(size*size); + for (unsigned int i = 0; i < size; ++i) + for (unsigned int j = 0; j < size; ++j) + lapack_A[i*size+j] = full_A(i,j); + + int info; //Variable containing information about the successfull exit of the lapack routine + char jobz = 'V'; //'V': all eigenpairs of A are computed + char uplo = 'U'; //storage format of the matrix A; not so important as matrix is symmetric + int LDA = size; //leading dimension of the matrix A + int lwork; //length of vector/array work + std::vector work (1); + + //by setting lwork to -1 a workspace query for work is done + //as matrix is symmetric: LDA == size of matrix + lwork = -1; + syev(&jobz, &uplo, &LDA, & *lapack_A.begin(), &LDA, & *eigenvalues_Lapack.begin(), & *work.begin(), &lwork, &info); + lwork=work[0]; + work.resize (lwork); + syev(&jobz, &uplo, &LDA, & *lapack_A.begin(), &LDA, & *eigenvalues_Lapack.begin(), & *work.begin(), &lwork, &info); + + AssertThrow (info==0, LAPACKSupport::ExcErrorCode("syev", info)); + for (int i=0; i eigenvalues_psyevx = scalapack_syevx.eigenpairs_symmetric_by_index(std::make_pair(size-max_n_eigenvalues,size-1),true); + scalapack_syevx.copy_to(p_eigenvectors); + for (unsigned int i=eigenvalues_psyevx.size()-1; i>0; --i) + { + if ( !(std::abs(eigenvalues_psyevx[i]-eigenvalues_Lapack[size-eigenvalues_psyevx.size()+i]) / + std::abs(eigenvalues_Lapack[size-eigenvalues_psyevx.size()+i]) < tol)) + { + std::cout << "process #" << this_mpi_process << ": eigenvalues do not fit: " + << eigenvalues_psyevx[i] << " <--> " << eigenvalues_Lapack[size-eigenvalues_psyevx.size()+i] << std::endl; + } + + AssertThrow ( std::abs(eigenvalues_psyevx[i]-eigenvalues_Lapack[size-eigenvalues_psyevx.size()+i]) / + std::abs(eigenvalues_Lapack[size-eigenvalues_psyevx.size()+i]) < tol, + ExcInternalError()); + } + pcout << " with respect to the given tolerance the eigenvalues coincide" << std::endl; + + // FIXME: run-time error on macOS if code between "pcout << comparing" and this line is executed. + // Happens at the end of the program run while freeing the MPI communicator. + + for (unsigned int i=0; i sizes = {{200,400,600}}; + const std::vector blocks = {{32,64}}; + + const double tol = 1e-10; + + for (const auto &s : sizes) + for (const auto &b : blocks) + if (b <= s) + test(s,b,tol); +} diff --git a/tests/scalapack/scalapack_06b.mpirun=1.output b/tests/scalapack/scalapack_06b.mpirun=1.output new file mode 100644 index 0000000000..1dc6a7a4e8 --- /dev/null +++ b/tests/scalapack/scalapack_06b.mpirun=1.output @@ -0,0 +1,30 @@ +200 32 1 1 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +200 64 1 1 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +400 32 1 1 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +400 64 1 1 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +600 32 1 1 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +600 64 1 1 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + diff --git a/tests/scalapack/scalapack_06b.mpirun=11.output b/tests/scalapack/scalapack_06b.mpirun=11.output new file mode 100644 index 0000000000..42d11a532d --- /dev/null +++ b/tests/scalapack/scalapack_06b.mpirun=11.output @@ -0,0 +1,30 @@ +200 32 3 3 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +200 64 3 3 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +400 32 3 3 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +400 64 3 3 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +600 32 3 3 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +600 64 3 3 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + diff --git a/tests/scalapack/scalapack_06b.mpirun=4.output b/tests/scalapack/scalapack_06b.mpirun=4.output new file mode 100644 index 0000000000..317fc67565 --- /dev/null +++ b/tests/scalapack/scalapack_06b.mpirun=4.output @@ -0,0 +1,30 @@ +200 32 2 2 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +200 64 2 2 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +400 32 2 2 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +400 64 2 2 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +600 32 2 2 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +600 64 2 2 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + diff --git a/tests/scalapack/scalapack_06b.mpirun=9.output b/tests/scalapack/scalapack_06b.mpirun=9.output new file mode 100644 index 0000000000..42d11a532d --- /dev/null +++ b/tests/scalapack/scalapack_06b.mpirun=9.output @@ -0,0 +1,30 @@ +200 32 3 3 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +200 64 3 3 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +400 32 3 3 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +400 64 3 3 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +600 32 3 3 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + +600 64 3 3 +comparing 5 eigenvalues and eigenvectors computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide + with respect to the given tolerance also the eigenvectors coincide + diff --git a/tests/scalapack/scalapack_06c.cc b/tests/scalapack/scalapack_06c.cc new file mode 100644 index 0000000000..c9632b703c --- /dev/null +++ b/tests/scalapack/scalapack_06c.cc @@ -0,0 +1,127 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 - 2018 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + +#include "../tests.h" +#include "../lapack/create_matrix.h" + +// test eigenpairs_symmetric_by_index(const std::pair &, const bool) +// for some eigenvalues without eigenvectors + + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + + +template +void test(const unsigned int size, const unsigned int block_size, const NumberType tol) +{ + MPI_Comm mpi_communicator(MPI_COMM_WORLD); + const unsigned int n_mpi_processes(Utilities::MPI::n_mpi_processes(mpi_communicator)); + const unsigned int this_mpi_process(Utilities::MPI::this_mpi_process(mpi_communicator)); + + ConditionalOStream pcout (std::cout, (this_mpi_process ==0)); + + std::shared_ptr grid = std::make_shared(mpi_communicator,size,size,block_size,block_size); + + pcout << size << " " << block_size << " " << grid->get_process_grid_rows() << " " << grid->get_process_grid_columns() << std::endl; + + const unsigned int n_eigenvalues = size; + const unsigned int max_n_eigenvalues = 5; + + // Create SPD matrices of requested size: + FullMatrix full_A(size); + std::vector eigenvalues_Lapack(size); + + ScaLAPACKMatrix scalapack_syevx (size, grid, block_size); + scalapack_syevx.set_property(LAPACKSupport::Property::symmetric); + + create_spd (full_A); + scalapack_syevx = full_A; + + //Lapack as reference + { + std::vector lapack_A(size*size); + for (unsigned int i = 0; i < size; ++i) + for (unsigned int j = 0; j < size; ++j) + lapack_A[i*size+j] = full_A(i,j); + + int info; //Variable containing information about the successfull exit of the lapack routine + char jobz = 'V'; //'V': all eigenpairs of A are computed + char uplo = 'U'; //storage format of the matrix A; not so important as matrix is symmetric + int LDA = size; //leading dimension of the matrix A + int lwork; //length of vector/array work + std::vector work (1); + + //by setting lwork to -1 a workspace query for work is done + //as matrix is symmetric: LDA == size of matrix + lwork = -1; + syev(&jobz, &uplo, &LDA, & *lapack_A.begin(), &LDA, & *eigenvalues_Lapack.begin(), & *work.begin(), &lwork, &info); + lwork=work[0]; + work.resize (lwork); + syev(&jobz, &uplo, &LDA, & *lapack_A.begin(), &LDA, & *eigenvalues_Lapack.begin(), & *work.begin(), &lwork, &info); + AssertThrow (info==0, LAPACKSupport::ExcErrorCode("syev", info)); + } + + // the actual test: + + pcout << "comparing " << max_n_eigenvalues << " eigenvalues computed using LAPACK and ScaLAPACK pdsyevx:" << std::endl; + const std::vector eigenvalues_psyevx = scalapack_syevx.eigenpairs_symmetric_by_index(std::make_pair(size-max_n_eigenvalues,size-1),false); + for (unsigned int i=eigenvalues_psyevx.size()-1; i>0; --i) + { + if ( !(std::abs(eigenvalues_psyevx[i]-eigenvalues_Lapack[size-eigenvalues_psyevx.size()+i]) / + std::abs(eigenvalues_Lapack[size-eigenvalues_psyevx.size()+i]) < tol)) + { + std::cout << "process #" << this_mpi_process << ": eigenvalues do not fit: " + << eigenvalues_psyevx[i] << " <--> " << eigenvalues_Lapack[size-eigenvalues_psyevx.size()+i] << std::endl; + } + + AssertThrow ( std::abs(eigenvalues_psyevx[i]-eigenvalues_Lapack[size-eigenvalues_psyevx.size()+i]) / + std::abs(eigenvalues_Lapack[size-eigenvalues_psyevx.size()+i]) < tol, + ExcInternalError()); + } + pcout << " with respect to the given tolerance the eigenvalues coincide" << std::endl; +} + + + +int main (int argc,char **argv) +{ + + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, numbers::invalid_unsigned_int); + + const std::vector sizes = {{200,400,600}}; + const std::vector blocks = {{32,64}}; + + const double tol = 1e-10; + + for (const auto &s : sizes) + for (const auto &b : blocks) + if (b <= s) + test(s,b,tol); +} diff --git a/tests/scalapack/scalapack_06c.mpirun=1.output b/tests/scalapack/scalapack_06c.mpirun=1.output new file mode 100644 index 0000000000..a305d9c1a9 --- /dev/null +++ b/tests/scalapack/scalapack_06c.mpirun=1.output @@ -0,0 +1,18 @@ +200 32 1 1 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +200 64 1 1 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +400 32 1 1 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +400 64 1 1 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +600 32 1 1 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +600 64 1 1 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide diff --git a/tests/scalapack/scalapack_06c.mpirun=11.output b/tests/scalapack/scalapack_06c.mpirun=11.output new file mode 100644 index 0000000000..e309d4e291 --- /dev/null +++ b/tests/scalapack/scalapack_06c.mpirun=11.output @@ -0,0 +1,18 @@ +200 32 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +200 64 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +400 32 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +400 64 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +600 32 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +600 64 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide diff --git a/tests/scalapack/scalapack_06c.mpirun=4.output b/tests/scalapack/scalapack_06c.mpirun=4.output new file mode 100644 index 0000000000..d514730e50 --- /dev/null +++ b/tests/scalapack/scalapack_06c.mpirun=4.output @@ -0,0 +1,18 @@ +200 32 2 2 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +200 64 2 2 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +400 32 2 2 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +400 64 2 2 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +600 32 2 2 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +600 64 2 2 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide diff --git a/tests/scalapack/scalapack_06c.mpirun=9.output b/tests/scalapack/scalapack_06c.mpirun=9.output new file mode 100644 index 0000000000..e309d4e291 --- /dev/null +++ b/tests/scalapack/scalapack_06c.mpirun=9.output @@ -0,0 +1,18 @@ +200 32 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +200 64 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +400 32 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +400 64 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +600 32 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide +600 64 3 3 +comparing 5 eigenvalues computed using LAPACK and ScaLAPACK pdsyevx: + with respect to the given tolerance the eigenvalues coincide -- 2.39.5