Commit d727f04e authored by PIACIBELLO Cyrille's avatar PIACIBELLO Cyrille

Comments updated and formatted

parent c64aea37
......@@ -46,7 +46,11 @@ public:
};
/**
* @brief Main Engine of the Library. Each method of the API exept for
* the init function is a memeber function of both this class and its
* parent's one.
*/
template<typename T,typename S=T>
class IbGMResDrEngine : public EngineDispatcher{
......@@ -63,6 +67,7 @@ class IbGMResDrEngine : public EngineDispatcher{
//Solution storage
Block<T,S>* sol;
Logger<S>* log;
public:
IbGMResDrEngine(void * userMatrix, int dim, void * inUserEnv) :
matrix(nullptr),
......
......@@ -17,8 +17,9 @@
* @param MaxKSize : Maximum size of Krylov Search space.
* @param epsilon : tolerance for Residual
* @param log : logger
* @param ortho : Choice of orthogonalization
*
* @return Number of iterations done
* @return Struct containing information about the procedure
*
* Solution will be stored inside X0 at the end of computation.
*
......
......@@ -16,8 +16,9 @@
* @param max_ite : number of iteration to do (at max)
* @param epsilon : tolerance for Residual
* @param log : logger
* @param ortho : Choice of orthogonalization
*
* @return Number of iterations done
* @return Struct containing information about the procedure
*
* Solution will be stored inside X0 at the end of computation.
*
......
......@@ -7,7 +7,8 @@
#include "Utils.hpp"
/**
* @brief : Arnoldi iterations
* @brief : Arnoldi iterations with incremental QR for least square
* resolution
*
* @param A : User Matrix
* @param X0 : Needed for computing real solution if convergence
......@@ -16,8 +17,9 @@
* @param MaxKSize : Maximum size of Krylov Search space.
* @param epsilon : tolerance for Residual
* @param log : logger
* @param ortho : Choice of orthogonalization
*
* @return Number of iterations done
* @return Struct containing information about the procedure
*
* Solution will be stored inside X0 at the end of computation.
*
......
......@@ -6,14 +6,19 @@
/**
* àbrief Enum over different available Orthogonalization scheme.
* @brief Enum over different available Orthogonalization scheme.
*/
enum class OrthoChoice{
MGS = 0,
CGS = 1,
IMGS = 2,
ICGS = 3
MGS = 0, /*!< Modified Gram Schmidt*/
CGS = 1, /*!< Classical Gram Schmidt*/
IMGS = 2, /*!< Iterated Modified Gram Schmidt*/
ICGS = 3 /*!< Iterated Classical Gram Schmidt*/
};
/**
* Overloading operator << for Enum in order to display the name of
* the scheme instead of the int corresponding.
*/
std::ostream& operator<<(std::ostream& os, const OrthoChoice& ortho){
switch(ortho){
case OrthoChoice::MGS:{ //Modified Gram Schmidt
......@@ -216,14 +221,11 @@ public:
*/
void ComputeMGSOrtho(Block<Scalar,Primary> & Wj, Scalar * HessToWrite, int ldHess,
int idxToStart = 0){
std::cout<<"Idx To Start :: "<<idxToStart<<"\n";
Scalar * ptrOfHess = HessToWrite;
int nbColinWj = Wj.getSizeBlock() - idxToStart;
//Loop over different blocks
for(int i=0 ; i< currentBlockUsed ; ++i){
int sizeCurrBlock = sumNbVectInBlock[i+1]-sumNbVectInBlock[i];
// std::cout<<"Ortho against block number "<<i<<" of size "
// <<sizeCurrBlock<<"\n";
//Compute hessenberg coeff
//Hij += V_i^{h} * W
......@@ -249,7 +251,10 @@ public:
}
/**
* @brief Orthogonalization process (Modified Gram Schmidt)
* @brief Orthogonalization process (Modified Gram Schmidt), Same
* as above, but we store the ortho coefficients inside a
* temporary block in order to be able to call this function twice
* in case of Iterated processus.
*
* @param Wj block to be orthogonalized against current base
* @param HessToWrite Array of Scalar to write the
......@@ -265,8 +270,6 @@ public:
//Loop over different blocks
for(int i=0 ; i< currentBlockUsed ; ++i){
int sizeCurrBlock = sumNbVectInBlock[i+1]-sumNbVectInBlock[i];
// std::cout<<"Ortho against block number "<<i<<" of size "
// <<sizeCurrBlock<<"\n";
//Create temp block
Block<Scalar,Primary> temp{nbColinWj,sizeCurrBlock};
......
......@@ -6,17 +6,17 @@
#include "LapackInterface.hpp"
/**
* @brief Will handle Wj
* @brief Will handle block of vectors
*
*/
template<class Scalar,typename Primary=Scalar>
class Block{
private:
int SizeBlock;
int TotalSize;
int ldb;
Scalar * datas;
int nbVectUsed;
int SizeBlock; /*!< Number of vectors stored*/
int TotalSize; /*!< Number of Scalar stored*/
int ldb; /*!< Leading dimension */
Scalar * datas;/*!< Raw datas*/
int nbVectUsed;/*!< number of vectors set*/
public:
Block() : SizeBlock(0),
TotalSize(0),
......@@ -25,6 +25,13 @@ public:
nbVectUsed(0){
}
/**
* @brief CTor
*
* @param : sizeBlock : number of vector to be stored
* @param : sizeVector : length of each vectors
*/
Block(int sizeBlock, int sizeVector) : SizeBlock(sizeBlock),
TotalSize(0),
ldb(sizeVector),
......@@ -37,13 +44,13 @@ public:
}
/**
* Move operator is deletd in order to avoid implicit moves
* @brief Move operator is deletd in order to avoid implicit moves
*/
Block<Scalar,Primary> & operator=(Block<Scalar,Primary> &&) = delete;
/**
* Will be used if default ctor is called, thus if we need to
* create the instance before knowing the size
* @brief Will be used if default ctor is called, thus if we need
* to create the instance before knowing the size
*/
void initData(int sizeBlock, int sizeVector){
SizeBlock = sizeBlock;
......@@ -53,12 +60,20 @@ public:
memset(datas,0,sizeof(Scalar)*TotalSize);
}
/**
* @brief DTor
*/
~Block(){
if(datas){
delete [] datas;
}
}
/**
* @brief Display all the vectors
*
* @param name : string to be displayed before displaying the Block
*/
void displayBlock(std::string name = ""){
std::cout<<name<<"\t LeadingDim x SizeBlock : "<<getLeadingDim()
<<" x "<<getSizeBlock()<<"\n";
......@@ -72,24 +87,54 @@ public:
std::cout<<std::endl;
}
/**
* @brief set to zero all the datas
*/
void reset(){
memset(datas,0,sizeof(Scalar)*TotalSize);
}
/**
* @brief Get the ptr to the starting point of the identified
* vector
*/
Scalar * getPtr(int idVect = 0){
return &datas[idVect*ldb];
}
/**
* @brief Return the Leading dimension
*/
int getLeadingDim(){
return ldb;
}
/**
* @brief Return the number of vector inside the Block
*/
int getSizeBlock(){
return SizeBlock;
}
//Lapack part
//QR facto
/**
* @brief Compute the QR factorization of a sub block and store
* the output matrices inside input Q and R.
*
* @param Q : Block that will contains the orthogonal vectors. Can
* be of size SizeBlock * dim, or of size dim*dim, if so, the full
* QR will be called, else, only a reduce QR will be called.
* @param R Block allocated that will hold the R part
* @param hStart : index to the vertical starting point of the sub block to
* be factorize
* @param vstart : index to the horizontal starting point of the sub block to
* be factorize
*/
void ComputeQRFacto(Block& Q, Block& R, //input are already allocated
int hStart=0, int vStart=0){ //if QR of part of block
......@@ -153,7 +198,7 @@ public:
}
/**
* Return the norm of id vector
* @brief Return the norm of id vector
*
*/
Primary getNorm(int id){
......@@ -167,6 +212,10 @@ public:
return norm2;
}
/**
* @brief Return the min and max norm over the vectors, normalize
* by normB
*/
std::pair<Primary,Primary> getMinMaxNorm(std::vector<Primary>& normB){
std::pair<Primary,Primary> minmax{100000,0};
for(int i=0 ; i<SizeBlock ; ++i){
......@@ -181,6 +230,9 @@ public:
return minmax;
}
/**
*@brief Return the min and max norm over the vectors
*/
std::pair<Primary,Primary> getMinMaxNorm(){
std::pair<Primary,Primary> minmax{100000,0};
for(int i=0 ; i<SizeBlock ; ++i){
......@@ -195,7 +247,9 @@ public:
return minmax;
}
/**
*@brief Check if all the vectors have a norm lesser than epsilon given
*/
bool CheckMultiPrecision(std::vector<Primary>& epsilon){
for(int i=0 ; i<SizeBlock ; ++i){
if (getNorm(i) > epsilon[i])
......@@ -207,7 +261,6 @@ public:
/**
* @brief Normalize all the column vectors of block and store the
* norm inside input norms.
*
*/
void Normalize(std::vector<Primary>& norms){
for(int i=0 ; i< SizeBlock ; ++i){
......
......@@ -42,6 +42,7 @@ public:
/**
* @brief Compute C = P^{H} * W and then W = W-C*P
*
* @param
*/
void OrthoWP(Scalar * toWrite, int ldToWrite){
if(cursor>0){
......
......@@ -5,18 +5,24 @@
#include <sys/time.h>
#include <functional>
/**
* @brief Struct containing information about one iterations
*/
template<class Primary>
struct LogIte{
int curr_ite;
int nbMatVect;
int currSizeBlock;
Primary min;
Primary max;
double timestamp;
int curr_ite; /*!< Index of Current iteration*/
int nbMatVect; /*!< Total Number of mat vect computed*/
int currSizeBlock; /*!< Number of vectors to extend the space at
this iteration*/
Primary min; /*!< Minimal norm reached at this iteration*/
Primary max; /*!< Maximum norm reached at this iteration*/
double timestamp; /*!< Time spent for this iteration */
};
/**
* @brief Class that will store informations during the solve at each
* iteration.
*/
template<class Primary,class Ite=LogIte<Primary>>//Primary will be double or float
class Logger{
int globalIte;
......@@ -36,6 +42,9 @@ public:
return iterations.size();
}
/**
* @brief Add an iteration to the list.
*/
void add_ite(int /*curr*/,int inSizeBlock,Primary min, Primary max,
double last_timestamp){
iterations.push_back(Ite{globalIte+1,currNbMatVect+inSizeBlock,inSizeBlock,
......@@ -45,12 +54,18 @@ public:
globalIte++;
}
/**
* @brief Static function to get a time stamp.
*/
static double GetTime(){
timeval t;
gettimeofday(&t, NULL);
return double(t.tv_sec) + (double(t.tv_usec)/1000000.0);
}
/**
* @brief iterator over the iterations.
*/
void forEachIte(std::function<void(int,int,int,Primary,Primary,double)> func){
for(auto & ite : iterations){
func(ite.curr_ite,ite.nbMatVect,ite.currSizeBlock, ite.min,ite.max,
......
......@@ -6,13 +6,15 @@
#include "Block.hpp"
/**
* @brief This struct will hold some output concerning an arnoldi
* procedure.
* @brief This struct store some output concerning a finished Arnoldi
* procedure
*
*/
struct ArnReturn{
int sizeKSpace;
int nbIteDone;
bool hasConverged;
int sizeKSpace; /*!< Size Krylov Space reached */
int nbIteDone; /*!< Number of iterations done */
bool hasConverged; /*!< Flag set to true if convergence has been
reached. */
};
/**
......
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