Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions benchmark/src/alien/benchmark/LinearBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <alien/move/handlers/scalar/VectorWriter.h>
#include <alien/move/data/Redistribution.h>

#include <alien/kernels/simple_csr/algebra/SimpleCSRLinearAlgebra.h>
//#include <alien/kernels/simple_csr/algebra/SimpleCSRLinearAlgebra.h>
#include <chrono>

namespace Alien::Benchmark
Expand Down Expand Up @@ -89,16 +89,16 @@ Alien::Move::VectorData LinearBench::_solve(Alien::Move::MatrixData&& linop, Ali

LinearBenchResults::LinearBenchResults(const LinearBench& bench, Alien::Move::VectorData&& solution)
{
SimpleCSRLinearAlgebra algebra;
//SimpleCSRLinearAlgebra algebra;

auto linop = bench.m_lp->matrix();

Alien::Move::VectorData residual(linop.distribution().rowDistribution());

auto rhs = bench.m_lp->vector();

algebra.mult(linop, solution, residual);
algebra.axpy(-1., rhs, residual);
//algebra.mult(linop, solution, residual);
//algebra.axpy(-1., rhs, residual);

m_solution = computeAnalytics(solution);
m_rhs = computeAnalytics(rhs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,14 +954,7 @@ directSendPack(const void* send_buffer,Int64 send_buffer_size,
MpiMessagePassingMng* MpiAdapter::
commSplit(bool keep)
{
MPI_Comm new_comm;

MPI_Comm_split(m_communicator, (keep) ? 1 : MPI_UNDEFINED, commRank(), &new_comm);
if (keep) {
// Failed if new_comm is MPI_COMM_NULL
return StandaloneMpiMessagePassingMng::create(new_comm, true);
}
return nullptr;
return StandaloneMpiMessagePassingMng::create(m_communicator, true);
}

/*---------------------------------------------------------------------------*/
Expand Down
5 changes: 4 additions & 1 deletion plugins/hypre/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ add_library(hypre_wrapper
src/hypre_vector.h
src/hypre_matrix.cpp
src/hypre_matrix.h
src/hypre_linear_algebra.cpp
src/hypre_linear_solver.cpp
src/backend.cpp
src/converters/hypre_to_simplecsr_vector.cpp
src/converters/hypre_to_simplecsr_vector.h
src/converters/simplecsr_to_hypre_vector.cpp
src/converters/simplecsr_to_hypre_vector.h
src/converters/simplecsr_to_hypre_matrix.cpp
src/converters/simplecsr_to_hypre_matrix.h
src/hypre_linear_solver.h)

target_link_libraries(hypre_wrapper PUBLIC
Expand Down
26 changes: 13 additions & 13 deletions plugins/hypre/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
#include <alien/benchmark/ILinearProblem.h>
#include <alien/benchmark/LinearBench.h>

#include <alien/hypre/backend.h>
#include <alien/hypre/options.h>
#include <alien/core/backend/BackEnd.h>
#include <alien/core/backend/LinearSolver.h>
#include "alien/expression/solver/SolverStat.h"

constexpr int NB_RUNS = 5;

int test(const Alien::Hypre::OptionTypes::eSolver& solv, const Alien::Hypre::OptionTypes::ePreconditioner& prec, const std::string& mat_filename, const std::string& vec_filename)
int test(const Alien::BackEnd::OptionTypes::eSolver& solv, const Alien::BackEnd::OptionTypes::ePreconditioner& prec, const std::string& mat_filename, const std::string& vec_filename)
{
auto* pm = Arccore::MessagePassing::Mpi::StandaloneMpiMessagePassingMng::create(MPI_COMM_WORLD);
auto* tm = Arccore::arccoreCreateDefaultTraceMng();
Expand All @@ -41,12 +41,12 @@ int test(const Alien::Hypre::OptionTypes::eSolver& solv, const Alien::Hypre::Opt
auto bench = Alien::Benchmark::LinearBench(std::move(problem));

for (int i = 0; i < NB_RUNS; i++) {
Alien::Hypre::Options options;
Alien::BackEnd::Options options;
options.numIterationsMax(500);
options.stopCriteriaValue(1e-8);
options.preconditioner(prec); // Jacobi, NoPC
options.solver(solv); //CG, GMRES, BICG, BICGSTAB
auto solver = Alien::Hypre::LinearSolver(options);
auto solver = Alien::LinearSolver("hypre");

tm->info() << "Running Hypre";
auto solution = bench.solve(&solver);
Expand Down Expand Up @@ -81,8 +81,8 @@ int main(int argc, char** argv)
}

// Default options, to run as test
auto solver = Alien::Hypre::OptionTypes::GMRES;
auto prec = Alien::Hypre::OptionTypes::DiagPC;
auto solver = Alien::BackEnd::OptionTypes::GMRES;
auto prec = Alien::BackEnd::OptionTypes::DiagPC;
std::string matrix_file = "matrix.mtx";
std::string vec_file = "rhs.mtx";

Expand All @@ -92,10 +92,10 @@ int main(int argc, char** argv)
else {
// Read the solver
if (std::string(argv[1]) == "CG") {
solver = Alien::Hypre::OptionTypes::CG;
solver = Alien::BackEnd::OptionTypes::CG;
}
else if (std::string(argv[1]) == "GMRES") {
solver = Alien::Hypre::OptionTypes::GMRES;
solver = Alien::BackEnd::OptionTypes::GMRES;
}
else {
std::cerr << "Unrecognized solver : " << argv[1] << "\n"
Expand All @@ -104,13 +104,13 @@ int main(int argc, char** argv)
}

if (std::string(argv[2]) == "Jacobi") {
prec = Alien::Hypre::OptionTypes::DiagPC;
prec = Alien::BackEnd::OptionTypes::DiagPC;
}
else if (std::string(argv[2]) == "NoPC") {
prec = Alien::Hypre::OptionTypes::NoPC;
prec = Alien::BackEnd::OptionTypes::NoPC;
}
else if (std::string(argv[2]) == "AMG") {
prec = Alien::Hypre::OptionTypes::AMGPC;
prec = Alien::BackEnd::OptionTypes::AMGPC;
}
else {
std::cerr << "Unrecognized preconditioner : " << argv[2] << "\n"
Expand Down Expand Up @@ -141,4 +141,4 @@ int main(int argc, char** argv)

MPI_Finalize();
return ret;
}
}
11 changes: 4 additions & 7 deletions plugins/hypre/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Copyright 2020 IFPEN-CEA
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.13)

Expand All @@ -25,19 +25,16 @@ find_package(Alien REQUIRED)
add_executable(example_hypre hypre_example_solve.cpp)

target_link_libraries(example_hypre PUBLIC
Alien::hypre_wrapper
Alien::alien_semantic_ref)

add_executable(example_hypre_move hypre_example_solve_move.cpp)

target_link_libraries(example_hypre_move PUBLIC
Alien::hypre_wrapper
Alien::alien_semantic_move)

add_executable(mm_driver_hypre driver_mm_hypre.cc)

target_link_libraries(mm_driver_hypre PUBLIC
Alien::hypre_wrapper
Alien::alien_semantic_move)

configure_file(msc00726.mtx msc00726.mtx COPYONLY)
Expand Down
38 changes: 19 additions & 19 deletions plugins/hypre/examples/driver_mm_hypre.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include <alien/move/AlienMoveSemantic.h>
#include <alien/move/handlers/scalar/VectorWriter.h>

#include <alien/hypre/backend.h>
#include <alien/hypre/options.h>
#include <alien/core/backend/BackEnd.h>
#include <alien/core/backend/LinearSolver.h>

int test(const std::string& filename)
{
Expand Down Expand Up @@ -51,46 +51,46 @@ int test(const std::string& filename)

Alien::Move::VectorData b(A.rowSpace(), A.distribution().rowDistribution());

Alien::Hypre::LinearAlgebra algebra;
//Alien::Hypre::LinearAlgebra algebra;

algebra.mult(A, xe, b);
//algebra.mult(A, xe, b);

Alien::Move::VectorData x(A.colSpace(), A.distribution().rowDistribution());

tm->info() << "* x = A^-1 b";

auto options = Alien::Hypre::Options()
.numIterationsMax(100)
.stopCriteriaValue(1e-10)
.preconditioner(Alien::Hypre::OptionTypes::AMGPC)
.solver(Alien::Hypre::OptionTypes::GMRES);
//auto options = Alien::Hypre::Options()
// .numIterationsMax(100)
// .stopCriteriaValue(1e-10)
// .preconditioner(Alien::Hypre::OptionTypes::AMGPC)
// .solver(Alien::Hypre::OptionTypes::GMRES);

auto solver = Alien::Hypre::LinearSolver(options);
auto solver = Alien::LinearSolver("hypre");

solver.solve(A, b, x);

{
tm->info() << "* r = Ax - b";

Alien::Move::VectorData r(A.rowSpace(), A.distribution().rowDistribution());
algebra.mult(A, x, r);
//algebra.mult(A, x, r);
tm->info() << "r -= b";
algebra.axpy(-1., b, r);
//algebra.axpy(-1., b, r);

auto norm = algebra.norm2(r);
auto norm_b = algebra.norm2(b);
//auto norm = algebra.norm2(r);
//auto norm_b = algebra.norm2(b);

tm->info() << " => ||r|| = " << norm << " ; ||r||/||b|| = " << norm / norm_b;
//tm->info() << " => ||r|| = " << norm << " ; ||r||/||b|| = " << norm / norm_b;
}

{
tm->info() << "|| x - xe ||";
algebra.axpy(-1., xe, x);
//algebra.axpy(-1., xe, x);

auto norm = algebra.norm2(x);
auto norm_xe = algebra.norm2(xe);
//auto norm = algebra.norm2(x);
//auto norm_xe = algebra.norm2(xe);

tm->info() << " => ||x-xe|| = " << norm << " ; ||r||/||b|| = " << norm / norm_xe;
//tm->info() << " => ||x-xe|| = " << norm << " ; ||r||/||b|| = " << norm / norm_xe;
}
tm->info() << " ";
tm->info() << "... example finished !!!";
Expand Down
57 changes: 32 additions & 25 deletions plugins/hypre/examples/hypre_example_solve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <alien/hypre/backend.h>

#include <arccore/message_passing_mpi/StandaloneMpiMessagePassingMng.h>

#include <alien/ref/AlienRefSemantic.h>

#include <alien/core/backend/BackEnd.h>
#include <alien/core/backend/LinearSolver.h>
//#include <alien/expression/solver/ILinearAlgebra.h>

int test()
{
auto* pm = Arccore::MessagePassing::Mpi::StandaloneMpiMessagePassingMng::create(MPI_COMM_WORLD);
Expand Down Expand Up @@ -73,9 +75,7 @@ int test()

Alien::Vector b(size, pm);

Alien::Hypre::LinearAlgebra algebra;

algebra.mult(A, xe, b);
//algebra.mult(A, xe, b);

Alien::Vector x(size, pm);

Expand All @@ -89,38 +89,45 @@ int test()
//
// auto solver = Alien::Hypre::LinearSolver (options);

auto solver = Alien::Hypre::LinearSolver();
//auto solver = Alien::Hypre::LinearSolver();

auto solver = Alien::LinearSolver("../libhypre_wrapper.so");
//auto solver2 = Alien::LinearSolver("../libhypre_wrapper.so");

std::cout << "foufou1" << std::endl;
MPI_Barrier(MPI_COMM_WORLD);
std::cout << "foufou2" << std::endl;

solver.solve(A, b, x);

tm->info() << "* r = Ax - b";

Alien::Vector r(size, pm);

{
Alien::Vector tmp(size, pm);
tm->info() << "t = Ax";
algebra.mult(A, x, tmp);
tm->info() << "r = t";
algebra.copy(tmp, r);
tm->info() << "r -= b";
algebra.axpy(-1., b, r);
}
//{
// Alien::Vector tmp(size, pm);
// tm->info() << "t = Ax";
// algebra.mult(A, x, tmp);
// tm->info() << "r = t";
// algebra.copy(tmp, r);
// tm->info() << "r -= b";
// algebra.axpy(-1., b, r);
//}

auto norm = algebra.norm2(r);
//auto norm = algebra.norm2(r);

tm->info() << " => ||r|| = " << norm;
//tm->info() << " => ||r|| = " << norm;

tm->info() << "* r = || x - xe ||";
//tm->info() << "* r = || x - xe ||";

{
tm->info() << "r = x";
algebra.copy(x, r);
tm->info() << "r -= xe";
algebra.axpy(-1., xe, r);
}
//{
// tm->info() << "r = x";
// algebra.copy(x, r);
// tm->info() << "r -= xe";
// algebra.axpy(-1., xe, r);
//}

tm->info() << " => ||r|| = " << norm;
tm->info() << " => ||r|| = "; // << norm;

tm->info() << " ";
tm->info() << "... example finished !!!";
Expand Down
Loading