Commit 4e66cd86 authored by BRAMAS Berenger's avatar BRAMAS Berenger

update hmat to prepare next stage

parent 1caa2656
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Berenger Bramas, Matthias Messner
// olivier.coulaud@inria.fr, berenger.bramas@inria.fr
// This software is a computer program whose purpose is to compute the FMM.
//
// This software is governed by the CeCILL-C and LGPL licenses and
// abiding by the rules of distribution of free software.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public and CeCILL-C Licenses for more details.
// "http://www.cecill.info".
// "http://www.gnu.org/licenses".
// ===================================================================================
#ifndef FBLOCKPMAPPING_HPP
#define FBLOCKPMAPPING_HPP
// @SCALFMM_PRIVATE
#include "Utils/FGlobal.hpp"
#include "Utils/FMath.hpp"
#include "Utils/FAssert.hpp"
#include "../Utils/FHUtils.hpp"
#include <functional>
#include <memory>
template <class FReal, class RowBlockClass, class ColBlockClass, class CoreCellClass >
class FBlockPMapping {
protected:
struct CellNode {
FBlockDescriptor infos;
CoreCellClass cell;
};
struct RowNode {
FBlockDescriptor infos;
RowBlockClass cell;
};
struct ColNode {
FBlockDescriptor infos;
ColBlockClass cell;
};
const int dim;
const int nbPartitions;
const int nbCells;
CellNode* cells;
RowNode* rowBlocks;
ColNode* colBlocks;
FBlockPMapping(const FBlockPMapping&) = delete;
FBlockPMapping& operator=(const FBlockPMapping&) = delete;
public:
explicit FBlockPMapping(const int inDim, const int partitions[], const int inNbPartitions)
: dim(inDim),
nbPartitions(inNbPartitions),
nbCells(inNbPartitions*inNbPartitions),
cells(nullptr){
FAssertLF(nbPartitions <= inDim);
FAssertLF(1 <= nbPartitions);
std::unique_ptr<int[]> partitionsOffset(new int[nbPartitions]);
partitionsOffset[0] = 0;
for(int idxPart = 1 ; idxPart < nbPartitions ; ++idxPart){
partitionsOffset[idxPart] = partitionsOffset[idxPart-1] + partitions[idxPart-1];
}
cells = new CellNode[nbCells];
for(int idxPartCol = 0 ; idxPartCol < nbPartitions ; ++idxPartCol){
for(int idxPartRow = 0 ; idxPartRow < nbPartitions ; ++idxPartRow){
cells[idxPartCol*nbPartitions + idxPartRow].infos.row = partitionsOffset[idxPartRow];
cells[idxPartCol*nbPartitions + idxPartRow].infos.col = partitionsOffset[idxPartCol];
cells[idxPartCol*nbPartitions + idxPartRow].infos.nbRows = partitions[idxPartRow];
cells[idxPartCol*nbPartitions + idxPartRow].infos.nbCols = partitions[idxPartCol];
cells[idxPartCol*nbPartitions + idxPartRow].infos.level = 0;
}
}
rowBlocks = new RowNode[nbPartitions];
for(int idxPartRow = 0 ; idxPartRow < nbPartitions ; ++idxPartRow){
rowBlocks[idxPartRow].infos.row = partitionsOffset[idxPartRow];
rowBlocks[idxPartRow].infos.col = 0;
rowBlocks[idxPartRow].infos.nbRows = partitions[idxPartRow];
rowBlocks[idxPartRow].infos.nbCols = dim;
rowBlocks[idxPartRow].infos.level = 0;
}
colBlocks = new ColNode[nbPartitions];
for(int idxPartCol = 0 ; idxPartCol < nbPartitions ; ++idxPartCol){
colBlocks[idxPartRow].infos.row = 0;
colBlocks[idxPartRow].infos.col = partitionsOffset[idxPartCol];
colBlocks[idxPartRow].infos.nbRows = dim;
colBlocks[idxPartRow].infos.nbCols = partitions[idxPartRow];
colBlocks[idxPartRow].infos.level = 0;
}
}
~FBlockPMapping(){
delete[] cells;
delete[] rowBlocks;
delete[] colBlocks;
}
int getNbBlocks() const {
return nbCells;
}
// Iterate blocks
CoreCellClass& getCell(const int idxRowPart, const int idxColPart){
return cells[idxColPart*nbPartitions + idxRowPart].cell;
}
const CoreCellClass& getCell(const int idxRowPart, const int idxColPart) const {
return cells[idxColPart*nbPartitions + idxRowPart].cell;
}
const FBlockDescriptor& getCellInfo(const int idxRowPart, const int idxColPart) const {
return cells[idxColPart*nbPartitions + idxRowPart].infos;
}
void forAllBlocksDescriptor(std::function<void(const FBlockDescriptor&)> callback){
for(int idxCell = 0 ; idxCell < nbCells ; ++idxCell){
callback(cells[idxCell].infos);
}
}
void forAllCellBlocks(std::function<void(const FBlockDescriptor&,
RowBlockClass&, CoreCellClass&, ColBlockClass&)> callback){
for(int idxPartCol = 0 ; idxPartCol < nbPartitions ; ++idxPartCol){
for(int idxPartRow = 0 ; idxPartRow < nbPartitions ; ++idxPartRow){
callback(cells[idxPartCol*nbPartitions + idxPartRow].infos,
cells[idxPartCol*nbPartitions + idxPartRow].cell,
rowBlocks[idxPartRow],
colBlocks[idxPartCol]);
}
}
}
// Iterate row blocks
RowBlockClass& getRowCell(const int idxRowPart){
return rowBlocks[idxRowPart].cell;
}
const RowBlockClass& getRowCell(const int idxRowPart) const {
return rowBlocks[idxRowPart].cell;
}
const FBlockDescriptor& getRowCellInfo(const int idxRowPart) const {
return rowBlocks[idxRowPart].infos;
}
// Iterate col blocks
ColBlockClass& getColCell(const int idxColPart){
return colBlocks[idxColPart].cell;
}
const ColBlockClass& getColCell(const int idxColPart) const {
return colBlocks[idxColPart].cell;
}
const ColBlockClass& getColCellInfo(const int idxColPart) const {
return colBlocks[idxColPart].infos;
}
// Operations
};
#endif // FBLOCKPMAPPING_HPP
......@@ -87,6 +87,11 @@ public:
FAssertLF(colIdx + nbRows <= matDim);
return FDenseBlockWrapper<FReal>(&values[colIdx*matDim+rowIdx], nbRows, nbCols, matDim);
}
FDenseBlockWrapper<FReal> getBlock(const FBlockDescriptor& info) const {
return getBlock(info.row, info.col, info.nbRows, info.nbCols);
}
};
#endif // FMATDENSE_HPP
......
......@@ -99,6 +99,10 @@ public:
FAssertLF(colIdx + nbCols <= matDim);
return FDenseBlockPermWrapper<FReal, FMatDensePerm<FReal> >(*this, rowIdx, colIdx, nbRows, nbCols);
}
FDenseBlockPermWrapper<FReal, FMatDensePerm<FReal> > getBlock(const FBlockDescriptor& info) const {
return getBlock(info.row, info.col, info.nbRows, info.nbCols);
}
};
#endif // FMATDENSEPERM_HPP
......
......@@ -16,7 +16,7 @@
// @SCALFMM_PRIVATE
#include "../Src/Containers/FPartitionsMapping.hpp"
#include "../Src/Containers/FBlockPMapping.hpp"
#include "../Src/Viewers/FMatDensePerm.hpp"
#include "../Src/Blocks/FDenseBlock.hpp"
......@@ -54,6 +54,16 @@ int main(int argc, char** argv){
}
}
{ // Here we fill the block manually
// We consider a fack permutation
std::unique_ptr<int[]> permutations(new int[dim]);
for(int idx = 0 ; idx < dim ; ++idx){
permutations[idx] = idx;
}
// Set permutation to matrix
matrix.setPermutOrigToNew(permutations.get());
}
std::unique_ptr<FReal[]> vec(new FReal[dim]);
for(int idxVal = 0 ; idxVal < dim ; ++idxVal){
vec[idxVal] = 1.0;
......@@ -71,7 +81,7 @@ int main(int argc, char** argv){
{
typedef FDenseBlock<FReal> CellClass;
typedef FPartitionsMapping<FReal, CellClass> GridClass;
typedef FBlockPMapping<FReal, CellClass, CellClass, CellClass> GridClass;
std::unique_ptr<int[]> partitions(new int[nbPartitions]);
{
......@@ -84,29 +94,22 @@ int main(int argc, char** argv){
}
GridClass grid(dim, partitions.get(), nbPartitions);
{ // Here we fill the block manually
// We consider a fack permutation
std::unique_ptr<int[]> permutations(new int[dim]);
for(int idx = 0 ; idx < dim ; ++idx){
permutations[idx] = idx;
}
// Set permutation to matrix
matrix.setPermutOrigToNew(permutations.get());
// We iterate on the blocks
for(int idxColBlock = 0 ; idxColBlock < nbPartitions ; ++idxColBlock){
for(int idxRowBlock = 0 ; idxRowBlock < nbPartitions ; ++idxRowBlock){
// We get the corresponding class
//>> CellClass& cl = grid.getCell(idxRowBlock, idxColBlock);
const FBlockDescriptor& info = grid.getCellInfo(idxRowBlock, idxColBlock);
// We iterate on its values
for(int idxColVal = 0 ; idxColVal < info.nbCols ; ++idxColVal){
for(int idxRowVal = 0 ; idxRowVal < info.nbRows ; ++idxRowVal){
//>> const FReal srcVal = matrix.getVal(idxRowVal, idxColVal);
}
}
}
// We iterate on the blocks
for(int idxColBlock = 0 ; idxColBlock < nbPartitions ; ++idxColBlock){
const MatrixClass::BlockDescriptor colBlock = matrix.getBlock(grid.getColCellInfo(idxColBlock));
// Store the result in grid.getColCell(idxColBlock)
}
for(int idxRowBlock = 0 ; idxRowBlock < nbPartitions ; ++idxRowBlock){
const MatrixClass::BlockDescriptor rowBlock = matrix.getBlock(grid.getRowCellInfo(idxRowBlock));
// Store the result in grid.getRowCell(idxRowBlock)
}
// Build the core part
for(int idxColBlock = 0 ; idxColBlock < nbPartitions ; ++idxColBlock){
for(int idxRowBlock = 0 ; idxRowBlock < nbPartitions ; ++idxRowBlock){
// Store the result in grid.getCell(idxRowBlock, idxColBlock)
}
}
......
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