Commit dd7d91e7 authored by Quentin Khan's avatar Quentin Khan

reorganized loadFMAAndRunFMM

parent 5e45de18
// ===================================================================================
// Copyright ScalFmm 2011 INRIA, Olivier Coulaud, Bérenger 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".
// ===================================================================================
#include <fstream> #include <fstream>
#include <memory> #include <memory>
#include <string> #include <string>
#include <sys/ioctl.h>
#include "Utils/FMath.hpp"
#include "Utils/FParameters.hpp" //#include "Utils/FMath.hpp"
#include "Utils/FParameterNames.hpp" //#include "Utils/FParameters.hpp"
//#include "Utils/FParameterNames.hpp"
#include "Files/FFmaGenericLoader.hpp" #include "Files/FFmaGenericLoader.hpp"
#include "Core/FFmmAlgorithm.hpp" #include "Core/FFmmAlgorithm.hpp"
#include "Kernels/Chebyshev/FChebSymKernel.hpp"
#include "Containers/FOctree.hpp" #include "Containers/FOctree.hpp"
#include "Components/FBasicCell.hpp" #include "Components/FBasicCell.hpp"
#include "Components/FSimpleLeaf.hpp" #include "Components/FSimpleLeaf.hpp"
#include "Components/FBasicParticleContainer.hpp" #include "Components/FBasicParticleContainer.hpp"
#include "Kernels/P2P/FP2PParticleContainerIndexed.hpp"
#include "FChebBalanceSymKernel.hpp"
#include "loadFMAAndRunFMMArgs.hpp" #include "loadFMAAndRunFMMArgs.hpp"
#include "loadFMAAndRunFMMUtils.hpp"
#include "FChebBalanceSymKernel.hpp"
#include "CostZones.hpp" #include "CostZones.hpp"
typedef FCostCell CellClass; using CellClass = FCostCell;
typedef FBasicParticleContainer<0> ContainerClass; using ContainerClass = FBasicParticleContainer<0>;
typedef FSimpleLeaf< ContainerClass > LeafClass; using LeafClass = FSimpleLeaf< ContainerClass >;
typedef FOctree< CellClass, ContainerClass, LeafClass > OctreeClass; using OctreeClass = FOctree< CellClass, ContainerClass, LeafClass >;
typedef FInterpMatrixKernelR MatrixKernelClass; using MatrixKernelClass = FInterpMatrixKernelR;
typedef FChebBalanceSymKernel<CellClass, using BalanceKernelClass= FChebBalanceSymKernel<CellClass, ContainerClass,
ContainerClass, MatrixKernelClass, 5,
MatrixKernelClass, OctreeClass>;
5, // using KernelClass = FChebSymKernel<CellClass, ContainerClass,
OctreeClass> KernelClass; // MatrixKernelClass, 5,
// OctreeClass>;
template < template <typename...> class T>
using AlgoClass = T <OctreeClass, CellClass, ContainerClass, BalanceKernelClass, LeafClass >;
const FReal epsilon = 1e-4; const FReal epsilon = 1e-4;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
loadFMAAndRunFMMArgs args(argc, argv); loadFMAAndRunFMMArgs args(argc, argv);
...@@ -42,62 +65,25 @@ int main(int argc, char** argv) ...@@ -42,62 +65,25 @@ int main(int argc, char** argv)
loader.getBoxWidth(), loader.getBoxWidth(),
loader.getCenterOfBox()); loader.getCenterOfBox());
FReal physicalValue; loadTree(tree, loader);
FPoint particlePosition;
// insertion BalanceKernelClass kernel(&tree, epsilon);
for ( int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart ) { AlgoClass<FFmmAlgorithm> costAlgo(&tree, &kernel);
loader.fillParticle(&particlePosition, &physicalValue);
tree.insert(particlePosition);
}
KernelClass kernel(&tree, epsilon);
FFmmAlgorithm<OctreeClass, CellClass, ContainerClass, KernelClass, LeafClass >
algo(&tree, &kernel);
algo.execute(); costAlgo.execute();
kernel.printResults(std::cout); if (args.verboseLevel() > 1) {
kernel.printResults(std::cout);
OctreeClass::Iterator it(&tree); }
CostZones<OctreeClass, CellClass> costzones(&tree, args.zoneCount()); CostZones<OctreeClass, CellClass> costzones(&tree, args.zoneCount());
costzones.run(); costzones.run();
// GCC versions before 5.0 have not implemented move constructors to streams writeZones(args, costzones);
std::vector<std::unique_ptr<std::ofstream>> outfiles;
for ( int zoneIdx = 0; zoneIdx < args.treeHeight(); zoneIdx++ ) { // AlgoClass<FFmmAlgorithmThreadBalanced> fmmAlgo();
std::unique_ptr<std::ofstream> out(
new std::ofstream( args.outFileName()
+ "_" + std::to_string(args.zoneCount()) + "z"
+ "." + std::to_string(zoneIdx)
+ args.outFileExt()));
*out << "x,y,z,zone" << std::endl;
outfiles.push_back(std::move(out));
}
auto zones = costzones.getZones();
int zoneIdx = 0;
for ( auto zone : zones) {
for ( auto cell : zone) {
*(outfiles[cell.first]) << cell.second->getCoordinate().getX() << ",";
*(outfiles[cell.first]) << cell.second->getCoordinate().getY() << ",";
*(outfiles[cell.first]) << cell.second->getCoordinate().getZ() << ",";
*(outfiles[cell.first]) << zoneIdx << "," << cell.first << std::endl;
}
zoneIdx++;
}
auto& zonebounds = costzones.getZoneBounds();
zoneIdx = 0;
for ( auto zone : zonebounds ) {
std::cout << std::endl << "Zone " << zoneIdx << std::endl;
int level = 0;
for ( auto levelbounds : zone ) {
std::cout << "Level" << level << " : [" << levelbounds.first << ":" << levelbounds.second << "]\n";
level++;
}
zoneIdx++;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
......
#ifndef _LOADFMAANDRUNFMMARGS_HPP_ #ifndef _LOADFMAANDRUNFMMARGS_HPP_
#define _LOADFMAANDRUNFMMARGS_HPP_ #define _LOADFMAANDRUNFMMARGS_HPP_
#include <sys/ioctl.h>
#include "tclap/CmdLine.h" #include "tclap/CmdLine.h"
#include "tclap/LinuxOutput.hpp" #include "tclap/LinuxOutput.hpp"
#include "tclap/CompletionVisitor.h" #include "tclap/CompletionVisitor.h"
...@@ -11,6 +13,7 @@ class loadFMAAndRunFMMArgs { ...@@ -11,6 +13,7 @@ class loadFMAAndRunFMMArgs {
const int _treeHeightInit = 5; const int _treeHeightInit = 5;
const int _subTreeHeightInit = 1; const int _subTreeHeightInit = 1;
const int _zoneCountInit = 4; const int _zoneCountInit = 4;
const int _verboseInit = 0;
const std::string _inFileNameInit = ""; const std::string _inFileNameInit = "";
const std::string _outFileNameInit = "balancetest"; const std::string _outFileNameInit = "balancetest";
const std::string _outFileNameExtInit = "csv"; const std::string _outFileNameExtInit = "csv";
...@@ -28,6 +31,12 @@ class loadFMAAndRunFMMArgs { ...@@ -28,6 +31,12 @@ class loadFMAAndRunFMMArgs {
"Show completion arguments", "Show completion arguments",
_cmd, false, &_compVistor}; _cmd, false, &_compVistor};
TCLAP::MultiSwitchArg
_verboseArg { "v",
"verbose",
"Activate verbosity",
_cmd, _verboseInit};
TCLAP::ValueArg <int> TCLAP::ValueArg <int>
_subTreeHeight { "", vs{"subtree-height", "sth"}, _subTreeHeight { "", vs{"subtree-height", "sth"},
...@@ -60,12 +69,13 @@ class loadFMAAndRunFMMArgs { ...@@ -60,12 +69,13 @@ class loadFMAAndRunFMMArgs {
"Input file name.", true, _inFileNameInit, "filename", _cmd}; "Input file name.", true, _inFileNameInit, "filename", _cmd};
public: public:
int treeHeight() {return _treeHeight.getValue();} int treeHeight() const {return _treeHeight.getValue();}
int subTreeHeight() {return _subTreeHeight.getValue();} int subTreeHeight() const {return _subTreeHeight.getValue();}
int zoneCount() {return _zoneCount.getValue();} int zoneCount() const {return _zoneCount.getValue();}
std::string inFileName() {return _inFileName.getValue();} int verboseLevel() const {return _verboseArg.getValue();}
std::string outFileName() {return _outFileName.getValue();} const std::string& inFileName() const {return _inFileName.getValue();}
std::string outFileExt() { const std::string& outFileName() const {return _outFileName.getValue();}
std::string outFileExt() const {
std::string ext = _outFileExt.getValue(); std::string ext = _outFileExt.getValue();
if ( ext.at(0) != '.' ) if ( ext.at(0) != '.' )
return '.' + ext; return '.' + ext;
......
#ifndef _LOADFMAANDRUNFMMUTILS_HPP_
#define _LOADFMAANDRUNFMMUTILS_HPP_
#include "CostZones.hpp"
template<class OctreeClass, class CellClass>
void writeZones(const loadFMAAndRunFMMArgs& args, const CostZones <OctreeClass,CellClass>& costzones)
{
// GCC versions before 5.0 have not implemented move constructors to streams
std::vector<std::unique_ptr<std::ofstream>> outfiles;
for ( int zoneIdx = 0; zoneIdx < args.treeHeight(); zoneIdx++ ) {
std::unique_ptr<std::ofstream> out(
new std::ofstream( args.outFileName()
+ "_" + std::to_string(args.zoneCount()) + "z"
+ "." + std::to_string(zoneIdx)
+ args.outFileExt()));
*out << "x,y,z,zone" << std::endl;
outfiles.push_back(std::move(out));
}
auto zones = costzones.getZones();
int zoneIdx = 0;
for ( auto zone : zones) {
for ( auto cell : zone) {
*(outfiles[cell.first]) << cell.second->getCoordinate().getX() << ",";
*(outfiles[cell.first]) << cell.second->getCoordinate().getY() << ",";
*(outfiles[cell.first]) << cell.second->getCoordinate().getZ() << ",";
*(outfiles[cell.first]) << zoneIdx << "," << cell.first << std::endl;
}
zoneIdx++;
}
if ( args.verboseLevel() > 0) {
auto& zonebounds = costzones.getZoneBounds();
zoneIdx = 0;
for ( auto zone : zonebounds ) {
std::cout << std::endl << "Zone " << zoneIdx << std::endl;
int level = 0;
for ( auto levelbounds : zone ) {
std::cout << "Level" << level << " : [" << levelbounds.first << ":" << levelbounds.second << "]\n";
level++;
}
zoneIdx++;
}
}
}
template <class OctreeClass>
void loadTree(OctreeClass& tree, FFmaGenericLoader& loader)
{
FReal physicalValue;
FPoint particlePosition;
// insertion
for ( int idxPart = 0 ; idxPart < loader.getNumberOfParticles() ; ++idxPart ) {
loader.fillParticle(&particlePosition, &physicalValue);
tree.insert(particlePosition);
}
}
#endif
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