Skip to content

Commit

Permalink
xx restore distrivute
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-iob committed May 27, 2024
1 parent d15224e commit fb5e7d2
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/LA_example_00001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ int run_restore(int rank, int nProcs)
AMGSystemSolver solver(transpose, multigrid, debug);

#if BITPIT_ENABLE_MPI==1
solver.restoreSystem(MPI_COMM_WORLD, ".", "LA_example_0001_linear_system_");
solver.restoreSystem(MPI_COMM_WORLD, false, ".", "LA_example_0001_linear_system_");
#else
solver.restoreSystem(".", "LA_example_0001_linear_system_");
#endif
Expand Down
2 changes: 1 addition & 1 deletion examples/LA_example_00002.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ int run_restore(int rank, int nProcs)
AMGSplitSystemSolver solver(transpose, multigrid, debug);

#if BITPIT_ENABLE_MPI==1
solver.restoreSystem(MPI_COMM_WORLD, ".", "LA_example_0002_linear_system_");
solver.restoreSystem(MPI_COMM_WORLD, false, ".", "LA_example_0002_linear_system_");
#else
solver.restoreSystem(".", "LA_example_0002_linear_system_");
#endif
Expand Down
56 changes: 44 additions & 12 deletions src/LA/system_solvers_large.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1714,16 +1714,27 @@ void SystemSolver::matrixDump(std::ostream &systemStream, const std::string &dir
* \param systemStream is the stream from which system information is read
* \param directory is the directory from which the matrix data file will be read
* \param prefix is the prefix that will be was added to the files during
*/
#if BITPIT_ENABLE_MPI==1
/*!
* \param redistribute if set to true, the matrix will be redistributed among the available
* processes, allowing to restore the matrix with a different number of processes than those
* used to dump it
*/
void SystemSolver::matrixRestore(std::istream &systemStream, const std::string &directory,
const std::string &prefix, bool redistribute)
#else
void SystemSolver::matrixRestore(std::istream &systemStream, const std::string &directory,
const std::string &prefix)
#endif
{
BITPIT_UNUSED(systemStream);

#if BITPIT_ENABLE_MPI==1
restoreMatrix(directory, prefix + "A", redistribute, &m_A);
#else
restoreMatrix(directory, prefix + "A", &m_A);
#endif
}

/*!
Expand Down Expand Up @@ -2154,21 +2165,21 @@ void SystemSolver::dumpSystem(const std::string &header, const std::string &dire
* files are found they will be re-created from scratch (but they will not be initialized).
*/
#if BITPIT_ENABLE_MPI==1
/*!
/*!
* \param communicator is the MPI communicator
* \param directory is the directory where the files will be read from
* \param prefix is the prefix that will be was added to the files during
* \param redistribute if set to true, the system will be redistributed among the available
* processes, allowing to restore the system with a different number of processes than those
* used to dump it
*/
void SystemSolver::restoreSystem(MPI_Comm communicator, const std::string &directory,
const std::string &prefix, bool redistribute)
#else
/*!
#endif
/*!
* \param directory is the directory where the files will be read from
* \param prefix is the prefix that will be was added to the files during
*/
#if BITPIT_ENABLE_MPI==1
void SystemSolver::restoreSystem(MPI_Comm communicator, bool redistribute,
const std::string &directory, const std::string &prefix)
#else
void SystemSolver::restoreSystem(const std::string &directory, const std::string &prefix)
#endif
{
Expand All @@ -2189,7 +2200,11 @@ void SystemSolver::restoreSystem(const std::string &directory, const std::string
restoreInfo(systemStream);

// Restore the matrix
#if BITPIT_ENABLE_MPI==1
matrixRestore(systemStream, directory, prefix, redistribute);
#else
matrixRestore(systemStream, directory, prefix);
#endif

// Restore RHS and solution vectors
vectorsRestore(systemStream, directory, prefix);
Expand Down Expand Up @@ -2433,16 +2448,25 @@ void SystemSolver::dumpMatrix(Mat matrix, const std::string &directory, const st
*
* \param directory is the directory from which the matrix data file will be read
* \param name is the name of the matrix that will be dumped
*/
#if BITPIT_ENABLE_MPI==1
/*!
* \param redistribute if set to true, the matrix will be redistributed among the available
* processes, allowing to restore the matrix with a different number of processes than those
* used to dump it
*/
#endif
/*!
* \param[out] matrix on output will contain the restored matrix
*/
#if BITPIT_ENABLE_MPI==1
void SystemSolver::restoreMatrix(const std::string &directory, const std::string &name,
bool redistribute, Mat *matrix) const
{
#if BITPIT_ENABLE_MPI==1
BITPIT_UNUSED(redistribute);
#else
void SystemSolver::restoreMatrix(const std::string &directory, const std::string &name,
Mat *matrix) const
{
#endif

// Create matrix
Expand Down Expand Up @@ -2787,17 +2811,25 @@ void SystemSolver::restoreVector(const std::string &directory, const std::string
*
* \param directory is the directory from which the vector data file will be read
* \param name is the name of the vector that will be dumped
*/
#if BITPIT_ENABLE_MPI==1
/*!
* \param redistribute if set to true, the vector will be redistributed among the available
* processes, allowing to restore the vector with a different number of processes than those
* used to dump it
*/
#endif
/*!
* \param[out] vector on output will contain the restored vector
*/
#if BITPIT_ENABLE_MPI==1
void SystemSolver::restoreVector(const std::string &directory, const std::string &name,
bool redistribute, Vec *vector) const
{
#if BITPIT_ENABLE_MPI==1
BITPIT_UNUSED(redistribute);
#else
void SystemSolver::restoreVector(const std::string &directory, const std::string &name,
Vec *vector) const
#endif
{

// Get size information
std::size_t localSize = std::numeric_limits<std::size_t>::max();
Expand Down
16 changes: 14 additions & 2 deletions src/LA/system_solvers_large.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ class SystemSolver {

void dumpSystem(const std::string &header, const std::string &directory, const std::string &prefix = "") const;
#if BITPIT_ENABLE_MPI==1
void restoreSystem(MPI_Comm communicator, const std::string &directory,
const std::string &prefix = "", bool redistribute = false);
void restoreSystem(MPI_Comm communicator, bool redistribute, const std::string &directory,
const std::string &prefix = "");
#else
void restoreSystem(const std::string &directory, const std::string &prefix = "");
#endif
Expand Down Expand Up @@ -377,7 +377,11 @@ class SystemSolver {
void matrixUpdate(long nRows, const long *rows, const Assembler &assembler);
virtual void matrixFill(const std::string &filePath);
virtual void matrixDump(std::ostream &systemStream, const std::string &directory, const std::string &prefix) const;
#if BITPIT_ENABLE_MPI==1
virtual void matrixRestore(std::istream &systemStream, const std::string &directory, const std::string &prefix, bool redistribute);
#else
virtual void matrixRestore(std::istream &systemStream, const std::string &directory, const std::string &prefix);
#endif
virtual void matrixDestroy();

virtual void vectorsCreate();
Expand Down Expand Up @@ -434,7 +438,11 @@ class SystemSolver {
void createMatrix(int rowBlockSize, int colBlockSize, int nNestedRows, int nNestedCols, Mat *subMatrices, Mat *matrix) const;
void fillMatrix(Mat matrix, const std::string &filePath) const;
void dumpMatrix(Mat matrix, const std::string &directory, const std::string &name) const;
#if BITPIT_ENABLE_MPI==1
void restoreMatrix(const std::string &directory, const std::string &name, bool redistribute, Mat *matrix) const;
#else
void restoreMatrix(const std::string &directory, const std::string &name, Mat *matrix) const;
#endif
void exportMatrix(Mat matrix, const std::string &filePath, FileFormat fileFormat) const;
void destroyMatrix(Mat *matrix) const;

Expand All @@ -446,7 +454,11 @@ class SystemSolver {
void dumpVector(Vec vector, const std::string &directory, const std::string &name) const;
void dumpVector(Vec vector, VectorSide side, const std::string &directory, const std::string &name) const;
void restoreVector(const std::string &directory, const std::string &name, Mat matrix, VectorSide side, Vec *vector) const;
#if BITPIT_ENABLE_MPI==1
void restoreVector(const std::string &directory, const std::string &name, bool redistribute, Vec *vector) const;
#else
void restoreVector(const std::string &directory, const std::string &name, Vec *vector) const;
#endif
void restoreVector(const std::string &directory, const std::string &name, std::size_t localSize, std::size_t globalSize, Vec *vector) const;
void exportVector(Vec vector, const std::string &filePath, FileFormat fileFormat) const;
void exportVector(Vec vector, std::vector<double> *data) const;
Expand Down
2 changes: 1 addition & 1 deletion test/integration_tests/LA/test_LA_00006.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ int subtest_002()
SplitSystemSolver solver(transpose, multigrid, debug);

#if BITPIT_ENABLE_MPI==1
solver.restoreSystem(MPI_COMM_WORLD, ".", "LA_example_0002_linear_system_");
solver.restoreSystem(MPI_COMM_WORLD, false, ".", "LA_example_0002_linear_system_");
#else
solver.restoreSystem(".", "LA_example_0002_linear_system_");
#endif
Expand Down
2 changes: 1 addition & 1 deletion test/integration_tests/LA/test_LA_parallel_00003.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int subtest_001(int rank, int nProcs)
log::cout() << "Restoring system..." << std::endl;

SystemSolver restoredSolver("", false);
restoredSolver.restoreSystem(MPI_COMM_WORLD, ".", "test_parallel_00003_");
restoredSolver.restoreSystem(MPI_COMM_WORLD, false, ".", "test_parallel_00003_");

long restoredGlobalNRows = restoredSolver.getRowGlobalCount();
long globalNRows = solver.getRowGlobalCount();
Expand Down
2 changes: 1 addition & 1 deletion test/integration_tests/LA/test_LA_parallel_00004.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ int subtest_002(int rank, int nProcs)
bool transpose = false;
SplitSystemSolver solver(transpose, multigrid, debug);

solver.restoreSystem(MPI_COMM_WORLD, ".", "LA_example_0002_linear_system_");
solver.restoreSystem(MPI_COMM_WORLD, false, ".", "LA_example_0002_linear_system_");
log::cout() << "Linear system restored." << std::endl;

// Export system
Expand Down

0 comments on commit fb5e7d2

Please sign in to comment.