// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: #include #include #include #include #include #include #include #include #include #include #if HAVE_MPI #include #include "mpi.h" #include #else #include #include "laplacian.hh" #endif #if HAVE_GMP template struct Dune::FloatCmp::EpsilonType> { typedef float Type; }; #endif template int testMatrixMarket(int N) { #if HAVE_MPI typedef int GlobalId; typedef Dune::OwnerOverlapCopyCommunication Communication; Communication comm(MPI_COMM_WORLD); std::cout << comm.communicator().rank() << " " << comm.communicator().size() << std::endl; int n; Matrix mat = setupAnisotropic2d(N, comm.indexSet(), comm.communicator(), &n, .011); #else Matrix mat; setupLaplacian(mat, N); #endif Vector bv(mat.N()), cv(mat.N()); int i=0; for(auto&& block : bv) for(auto&& entry : Dune::Impl::asVector(block)) entry = (i++); using R = typename Dune::FieldTraits::real_type; int prec = std::numeric_limits::is_specialized ? std::numeric_limits::max_digits10 : std::numeric_limits::max_digits10; R eps = std::numeric_limits::is_specialized ? std::numeric_limits::epsilon() : R(std::numeric_limits::epsilon()) ; #if HAVE_MPI comm.remoteIndices().rebuild(); comm.copyOwnerToAll(bv,bv); Dune::OverlappingSchwarzOperator op(mat, comm); op.apply(bv, cv); storeMatrixMarket(mat, std::string("testmat"), comm, true, prec); storeMatrixMarket(bv, std::string("testvec"), comm, false, prec); #else typedef Dune::MatrixAdapter Operator; Operator op(mat); op.apply(bv, cv); storeMatrixMarket(mat, std::string("testmat"), prec); storeMatrixMarket(bv, std::string("testvec"), prec); #endif Matrix mat1; Vector bv1,cv1; #if HAVE_MPI Communication comm1(MPI_COMM_WORLD); loadMatrixMarket(mat1, std::string("testmat"), comm1); loadMatrixMarket(bv1, std::string("testvec"), comm1, false); #else loadMatrixMarket(mat1, std::string("testmat")); loadMatrixMarket(bv1, std::string("testvec")); #endif int ret=0; if(mat.N()!=mat1.N() || mat.M()!=mat1.M()) { ++ret; std::cerr<<"matrix sizes do not match"<begin(), col1=row1->begin(); col!= row->end(); ++col, ++col1) { if(col.index()!=col1.index()) { std::cerr <<"Column indices do not match"< eps)) { std::cerr<<"written and read vector do not match"< op1(mat1, comm1); op1.apply(bv1, cv1); if(comm1.indexSet()!=comm.indexSet()) { std::cerr<<"written and read idxset do not match"< Operator; Operator op1(mat1); op1.apply(bv1, cv1); #endif for (auto entry=cv.begin(), entry1=cv1.begin(); cv.end() != entry; ++entry, ++entry1) if (Dune::Simd::anyTrue(abs(*entry - *entry1) > eps)) { std::cerr<<"computed vectors do not match: " << *entry << " != " << *entry1 <1) N = atoi(argv[1]); std::cout << "testing for N=" << N << " BS=" << BS << std::endl; // Test scalar matrices and vectors int ret = testMatrixMarket, Dune::BlockVector >(N); #if HAVE_MPI if(ret!=0) MPI_Abort(MPI_COMM_WORLD, ret); #endif // Test block matrices and vectors with trivial blocks typedef Dune::FieldMatrix MatrixBlock; typedef Dune::BCRSMatrix BCRSMat; typedef Dune::FieldVector VectorBlock; typedef Dune::BlockVector BVector; ret |= testMatrixMarket(N); // test for vector with multiple lanes typedef Dune::BlockVector> BVectorSIMD; ret |= testMatrixMarket, BVectorSIMD>(N); // Test other field types #if HAVE_QUADMATH std::cout << "Test Float128" << std::endl; ret |= testMatrixMarket, Dune::BlockVector>(N); #endif #if HAVE_GMP std::cout << "Test GMPField" << std::endl; ret |= testMatrixMarket>, Dune::BlockVector>>(N); #endif #if HAVE_MPI if(ret!=0) MPI_Abort(MPI_COMM_WORLD, ret); #endif #if HAVE_MPI MPI_Finalize(); #endif return ret; }