Files
LBPM/analysis/runAnalysis.h

146 lines
5.2 KiB
C
Raw Normal View History

2018-06-11 15:19:05 -04:00
/*
Copyright 2013--2018 James E. McClure, Virginia Polytechnic & State University
2020-10-12 06:08:29 -04:00
Copyright Equnior ASA
2018-06-11 15:19:05 -04:00
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM 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 License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
2018-03-08 13:03:22 -05:00
#ifndef RunAnalysis_H_INC
#define RunAnalysis_H_INC
2019-03-19 16:36:02 -04:00
#include "analysis/SubPhase.h"
2021-01-22 10:05:16 -05:00
#include "analysis/TwoPhase.h"
#include "analysis/analysis.h"
2018-03-08 13:03:22 -05:00
#include "common/Communication.h"
#include "common/ScaLBL.h"
#include "threadpool/thread_pool.h"
#include "models/ColorModel.h"
2019-03-26 15:59:04 -04:00
#include <limits.h>
2018-03-08 13:03:22 -05:00
// Types of analysis
2021-01-22 10:05:16 -05:00
enum class AnalysisType : uint64_t {
AnalyzeNone = 0,
IdentifyBlobs = 0x01,
CopyPhaseIndicator = 0x02,
CopySimState = 0x04,
ComputeAverages = 0x08,
CreateRestart = 0x10,
WriteVis = 0x20,
ComputeSubphase = 0x40
};
2018-03-08 13:03:22 -05:00
//! Class to run the analysis in multiple threads
class runAnalysis
{
public:
//! Constructor
2021-01-22 10:05:16 -05:00
runAnalysis( std::shared_ptr<Database> db, const RankInfoStruct &rank_info,
std::shared_ptr<ScaLBL_Communicator> ScaLBL_Comm, std::shared_ptr<Domain> dm, int Np,
bool Regular, IntArray Map );
runAnalysis( ScaLBL_ColorModel &ColorModel);
2018-03-08 13:03:22 -05:00
//! Destructor
~runAnalysis();
//! Run the next analysis
2021-01-22 10:05:16 -05:00
void run( int timestep, std::shared_ptr<Database> db, TwoPhase &Averages, const double *Phi,
2018-03-08 13:03:22 -05:00
double *Pressure, double *Velocity, double *fq, double *Den );
2021-01-22 10:05:16 -05:00
void basic( int timestep, std::shared_ptr<Database> db, SubPhase &Averages, const double *Phi,
double *Pressure, double *Velocity, double *fq, double *Den );
void WriteVisData( int timestep, std::shared_ptr<Database> vis_db, SubPhase &Averages,
const double *Phi, double *Pressure, double *Velocity, double *fq, double *Den );
2018-03-08 13:03:22 -05:00
//! Finish all active analysis
void finish();
/*!
* \brief Set the affinities
* \details This function will create the analysis threads and set the affinity
* of this thread and all analysis threads. If MPI_THREAD_MULTIPLE is not
2021-01-22 10:05:16 -05:00
* enabled, the analysis threads will be disabled and the analysis will run in the current
* thread.
2018-03-08 13:03:22 -05:00
* @param[in] method Method used to control the affinities:
* none - Don't use threads (runs all analysis in the current thread)
* default - Create the specified number of threads, but don't load balance
* independent - Create the necessary number of threads to fill all cpus,
* and set the affinities based on the current process such
* that all threads run on independent cores
* @param[in] N_threads Number of threads, only used by some of the methods
2018-03-08 13:03:22 -05:00
*/
2021-01-22 10:05:16 -05:00
void createThreads( const std::string &method = "default", int N_threads = 4 );
2018-03-08 13:03:22 -05:00
private:
runAnalysis();
// Determine the analysis to perform
AnalysisType computeAnalysisType( int timestep );
public:
class commWrapper
{
2021-01-22 10:05:16 -05:00
public:
2021-01-04 23:35:10 -05:00
Utilities::MPI comm;
2018-03-08 13:03:22 -05:00
int tag;
runAnalysis *analysis;
2021-01-22 10:05:16 -05:00
commWrapper( int tag, const Utilities::MPI &comm, runAnalysis *analysis );
commWrapper() = delete;
2018-03-08 13:03:22 -05:00
commWrapper( const commWrapper &rhs ) = delete;
2021-01-22 10:05:16 -05:00
commWrapper &operator=( const commWrapper &rhs ) = delete;
2018-03-08 13:03:22 -05:00
commWrapper( commWrapper &&rhs );
~commWrapper();
};
// Get a comm (not thread safe)
2021-01-22 10:05:16 -05:00
commWrapper getComm();
2018-03-08 13:03:22 -05:00
private:
2021-01-22 10:05:16 -05:00
std::array<int, 3> d_n; // Number of local cells
std::array<int, 3> d_N; // Number of local cells with ghosts
2018-03-08 13:03:22 -05:00
int d_Np;
int d_rank;
2018-05-15 11:59:01 -04:00
int d_restart_interval, d_analysis_interval, d_blobid_interval, d_visualization_interval;
2019-03-26 15:53:11 -04:00
int d_subphase_analysis_interval;
2018-03-08 13:03:22 -05:00
double d_beta;
2018-07-06 09:16:11 -04:00
bool d_regular;
std::string format; // IO format string "silo" or "hdf5"
2018-03-08 13:03:22 -05:00
ThreadPool d_tpool;
RankInfoStruct d_rank_info;
IntArray d_Map;
2021-01-22 10:05:16 -05:00
std::shared_ptr<std::pair<int, IntArray>> d_last_ids;
std::shared_ptr<std::pair<int, IntArray>> d_last_index;
std::shared_ptr<std::vector<BlobIDType>> d_last_id_map;
2018-03-08 13:03:22 -05:00
std::vector<IO::MeshDataStruct> d_meshData;
std::string d_restartFile;
2021-01-04 23:35:10 -05:00
Utilities::MPI d_comm;
Utilities::MPI d_comms[1024];
2018-03-08 13:03:22 -05:00
volatile bool d_comm_used[1024];
2018-05-17 09:36:34 -04:00
std::shared_ptr<ScaLBL_Communicator> d_ScaLBL_Comm;
2018-03-08 13:03:22 -05:00
// Ids of work items to use for dependencies
ThreadPool::thread_id_t d_wait_blobID;
ThreadPool::thread_id_t d_wait_analysis;
2019-03-26 15:55:34 -04:00
ThreadPool::thread_id_t d_wait_subphase;
2018-03-08 13:03:22 -05:00
ThreadPool::thread_id_t d_wait_vis;
ThreadPool::thread_id_t d_wait_restart;
// Friends
friend commWrapper::~commWrapper();
};
#endif