Commit ed50c6fa authored by PIACIBELLO Cyrille's avatar PIACIBELLO Cyrille

API updated, using now the BGMRes + Arnoldi procedure system

parent 62a4cdbf
......@@ -2,8 +2,11 @@
#define IBGMRESENGINE_HPP
#include "UserMatrix.hpp"
#include "../src/BlockGMResQR.hpp"
#include "../src/IBGMRes.hpp"
#include "../src/Utils.hpp"
#include "../src/Logger.hpp"
#include "../src/Arnoldi_QRInc.hpp"
#include "../src/Arnoldi_IB.hpp"
#include "../src/BGMRes.hpp"
/**
* @brief This class is used to dereference the handle given by the
* user without knowing in which arithmetic we are.
......@@ -55,7 +58,7 @@ class IbGMResDrEngine : public EngineDispatcher{
//Solution storage
Block<T,S>* sol;
Logger<S,5>* log;
Logger<S>* log;
public:
IbGMResDrEngine(void * userMatrix, int dim, void * inUserEnv) :
matrix(nullptr),
......@@ -101,14 +104,15 @@ public:
//Convert raw data to Block
Block<T,S> X_init(nbRHS,matrix->size());
Block<T,S> B(nbRHS,matrix->size());
X_init.InitBlock(reinterpret_cast<T*>(X0));
B.InitBlock(reinterpret_cast<T*>(RHS));
ConvertStructures(RHS,X0,B,X_init);
//Init an empty block to store solution
sol = new Block<T,S>(nbRHS,matrix->size());
log = new Logger<S,5>();
//Call to BlockGMRes with parameters
int res = BlockGMResQR<UserMatrix<T,S>,T,S>(*matrix,B,X_init,max_iter,*sol,
restart,*log,tolerance);
log = new Logger<S>();
//Compute
using Arnoldi = Arnoldi_QRInc<UserMatrix<T,S>,T,S>;
int res = call_solve<Arnoldi>(B,X_init,*sol,*log);
return res;
}
......@@ -116,13 +120,29 @@ public:
//Convert raw data to Block
Block<T,S> X_init(nbRHS,matrix->size());
Block<T,S> B(nbRHS,matrix->size());
X_init.InitBlock(reinterpret_cast<T*>(X0));
B.InitBlock(reinterpret_cast<T*>(RHS));
ConvertStructures(RHS,X0,B,X_init);
//Init an empty block to store solution
sol = new Block<T,S>(nbRHS,matrix->size());
log = new Logger<S,5>();
int res = IBGMRes<UserMatrix<T,S>,T,S,5>(*matrix,B,X_init,
max_iter,restart,*sol,*log);
log = new Logger<S>();
//Compute
using Arnoldi = Arnoldi_IB<UserMatrix<T,S>,T,S>;
int res = call_solve<Arnoldi>(B,X_init,*sol,*log);
return res;
}
void ConvertStructures(void * RHS,void *X0,
Block<T,S>& B,Block<T,S>& X_init){
X_init.InitBlock(reinterpret_cast<T*>(X0));
B.InitBlock(reinterpret_cast<T*>(RHS));
}
template<class Arn>
int call_solve(Block<T,S>& B,Block<T,S>& X0,Block<T,S> & sol,Logger<S>& log){
int res = BGMRes<Arn,UserMatrix<T,S>,T,S>(*matrix,B,X0,
max_iter,restart,
sol,log,tolerance);
return res;
}
......@@ -136,8 +156,9 @@ public:
double* get_logs()override{
if(log){
double * res = log->writeDownArray();
return res;
//double * res = log->writeDownArray();
//return res;
return nullptr;
}else{
return nullptr;
}
......
......@@ -100,9 +100,9 @@ int main(int ac, char ** av){
double tol = 0.001;
ibgmresdr_set_parameters(5,5,&tol,handle);
ibgmresdr_set_parameters(5,20,&tol,handle);
int nb_iter = ibgmresdr_solve(userEnv->nbRHS,RHS,X0,handle);
int nb_iter = ibgmresdr_solve_IB(userEnv->nbRHS,RHS,X0,handle);
double * res = ibgmresdr_get_results(handle);
......@@ -110,6 +110,7 @@ int main(int ac, char ** av){
free(userEnv);
free(RHS);
free(X0);
free(my_matrix->datas);
free(my_matrix);
......
......@@ -133,7 +133,7 @@ int main(int ac , char ** av){
double tol = 0.000001;
//set param : nb_iter, restart, ptr to tolerance
ibgmresdr_set_parameters((mat->dim1)/userEnv->nbRHS, //nb max ite
((mat->dim1)/userEnv->nbRHS), //size of restart
1000, //size of restart
&tol, handle);
......
......@@ -68,10 +68,13 @@ int BGMRes(Matrix& A,Block<Scalar,Primary>& B, Block<Scalar,Primary>& X0,
//Call Arnoldi's procedure specified in template
ArnReturn ret = Arn::Exec_Procedure(A,X0,B,arnoldi_ite,MaxKSize,epsilon,log);
nbIteDone+=ret.nbIteDone;
std::cout<<"\n################## Restart Done "<<nb_restart
<<" #################\n";
std::cout<<"\n################## Total iterations "<<nbIteDone
<<" #################\n";
nbIteDone+=ret.nbIteDone;
//Three case :
//--1 Arnoldi converged
//--2 Arnoldi reached Max Krylov Size allowed
......
......@@ -12,6 +12,7 @@ set(GMRES_TEST_SRC
testIbBGMRes.cpp
testQRIncrementalGMRes.cpp
testBGMRes.cpp
testMatrixIW_noRHS.cpp
)
#set(LIBS_FOR_TESTS ibgmresdr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment