Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPIO support for Basis classes #274

Merged
merged 53 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b6a9ac6
BasisWriter::writeBasis create/open a file and closes the file at the…
dreamer2368 Jan 17, 2024
e5c7779
stylization.
dreamer2368 Jan 17, 2024
fd53d75
HDFDatabase::putIntegerArray - overwrites if the dataset exists.
dreamer2368 Jan 17, 2024
302823a
enforce single time interval in Options.
dreamer2368 Feb 9, 2024
14cbb89
HDFDatabase::putIntegerArray does not allow overwrite.
dreamer2368 Feb 9, 2024
b799317
BasisWriter::writeBasis always create the file, which will overwrite …
dreamer2368 Feb 9, 2024
6d2067a
add a header and stylization.
dreamer2368 Feb 9, 2024
dc63042
remove increase time interval test, as time interval is fixed to 1.
dreamer2368 Feb 9, 2024
8d84c1b
add an error message for a guidance.
dreamer2368 Feb 15, 2024
85aa021
remove test_SVD from ci workflow.
dreamer2368 Feb 15, 2024
3c3c667
SVD::increaseTimeInterval - allow the initial time interval.
dreamer2368 Feb 15, 2024
8371e85
minor fix in test_IncrementalSVDBrand.
dreamer2368 Feb 15, 2024
bf1e126
reflecting the comments.
dreamer2368 Feb 16, 2024
cf6f27c
removed the concept of time interval in BasisReader. time argument re…
dreamer2368 Feb 17, 2024
3153eaf
BasisWriter: removed the concept of time interval.
dreamer2368 Feb 17, 2024
6ffa908
minor fix in BasisReader.
dreamer2368 Feb 17, 2024
8aa426d
SVD: removed the concept of time intervals.
dreamer2368 Feb 17, 2024
b7cb8e2
BasisGenerator: removed the concept of time interval.
dreamer2368 Feb 17, 2024
3d43de0
add test_SVD.cpp for resolving conflict.
dreamer2368 Feb 17, 2024
9fdc453
stylization.
dreamer2368 Feb 17, 2024
3acb606
changed function signature of BasisGenerator::takeSample.
dreamer2368 Feb 21, 2024
79702a2
rebased to resolve conflict.
dreamer2368 Feb 21, 2024
5889309
changed function signature for BasisReader::getSpatialBasis.
dreamer2368 Feb 21, 2024
5e3a418
changed function signature for BasisReader::getTemporalBasis.
dreamer2368 Feb 21, 2024
99beadb
changed function signature for BasisReader::getSingularValues.
dreamer2368 Feb 21, 2024
30ff855
changed function signature for BasisReader::getSnapshotMatrix.
dreamer2368 Feb 21, 2024
7eb2044
unit test with fapl_mpi.
dreamer2368 Feb 16, 2024
6e809f2
parallel integer array writing example.
dreamer2368 Feb 16, 2024
dd17b60
add timing for H5DWrite.
dreamer2368 Feb 16, 2024
3f43c62
2d integer array parallel writing example.
dreamer2368 Feb 16, 2024
fc51f9e
hdf5 parallel integer array reading example.
dreamer2368 Feb 16, 2024
62366be
add d_dim as const member variable of BasisGenerator/Reader.
dreamer2368 Feb 17, 2024
cd347ec
BasisReader: CSV format is never used. Enforce HDF5 format from now on.
dreamer2368 Feb 17, 2024
281eb9a
create/open_parallel function.
dreamer2368 Feb 17, 2024
a6f8c12
stylization
dreamer2368 Feb 17, 2024
472a3e5
test_HDFDatabase: test for selective parallal I/O.
dreamer2368 Feb 20, 2024
17f0438
parallel I/O routines within basis classes.
dreamer2368 Feb 20, 2024
2806f8e
HDFDatabaseMPIO class initial loading.
dreamer2368 Feb 21, 2024
bf6fa22
rebase from generator-fix2
dreamer2368 Feb 21, 2024
efe2f71
deployed HDFDatabaseMPIO to basis classes.
dreamer2368 Feb 21, 2024
736bc11
test for partial getSpatialBasis.
dreamer2368 Feb 22, 2024
2123862
test routien for scaling.
dreamer2368 Feb 22, 2024
945995f
add hdf database test in ci workflow.
dreamer2368 Feb 22, 2024
66a4785
Merge remote-tracking branch 'origin/master' into mpi-io
dreamer2368 Feb 29, 2024
f36fbb4
update doxygen description
dreamer2368 Feb 29, 2024
0d0ce60
Merge branch 'master' into mpi-io
dreamer2368 Mar 5, 2024
41d57c5
reflecting comments 1
dreamer2368 Mar 13, 2024
d91bb90
reflecting comments 2. changed interface.
dreamer2368 Mar 14, 2024
49095d5
Merge branch 'master' into mpi-io
dreamer2368 Mar 14, 2024
0d883f1
minor fix
dreamer2368 Mar 14, 2024
09b8271
reflecting comments
dreamer2368 Mar 18, 2024
fdff1ff
hdf5 parallel is optional. set compile-time if statements.
dreamer2368 Mar 18, 2024
a339294
minor fix
dreamer2368 Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/run_tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ runs:
mpirun -n 3 --oversubscribe tests/test_StaticSVD
./tests/test_IncrementalSVDBrand
mpirun -n 3 --oversubscribe tests/test_IncrementalSVDBrand
./tests/test_HDFDatabase
mpirun -n 3 --oversubscribe tests/test_HDFDatabase
./tests/test_NNLS
mpirun -n 3 --oversubscribe tests/test_NNLS
shell: bash
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ if(GTEST_FOUND)
set(unit_test_stems
Vector
Matrix
HDFDatabase
DEIM
DMD
GNAT
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WORKDIR /$ENVDIR
# install packages
RUN sudo apt-get install -yq git
RUN sudo apt-get install --no-install-recommends -yq make gcc gfortran libssl-dev cmake
RUN sudo apt-get install -yq libopenblas-dev libmpich-dev libblas-dev liblapack-dev libscalapack-mpi-dev libhdf5-serial-dev
RUN sudo apt-get install -yq libopenblas-dev libmpich-dev libblas-dev liblapack-dev libscalapack-mpi-dev libhdf5-mpi-dev hdf5-tools
RUN sudo apt-get install -yq vim
RUN sudo apt-get install -yq git-lfs
RUN sudo apt-get install -yq valgrind
Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ set(module_list
hyperreduction/Hyperreduction
utils/Database
utils/HDFDatabase
utils/HDFDatabaseMPIO
utils/CSVDatabase
utils/Utilities
utils/ParallelBuffer
Expand Down
3 changes: 2 additions & 1 deletion lib/linalg/BasisGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ BasisGenerator::BasisGenerator(
bool incremental,
const std::string& basis_file_name,
Database::formats file_format) :
d_dim(options.dim),
d_incremental(incremental),
d_basis_writer(0),
d_basis_reader(0),
Expand Down Expand Up @@ -153,7 +154,7 @@ BasisGenerator::loadSamples(const std::string& base_file_name,

if (d_basis_reader) delete d_basis_reader;

d_basis_reader = new BasisReader(base_file_name, db_format);
d_basis_reader = new BasisReader(base_file_name, db_format, d_dim);
const Matrix* mat;
const Vector* singular_vals;

Expand Down
9 changes: 8 additions & 1 deletion lib/linalg/BasisGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class BasisGenerator
int
getDim()
{
return d_svd->getDim();
return d_dim;
}

/**
Expand Down Expand Up @@ -342,6 +342,13 @@ class BasisGenerator
* @brief The number of processors being run on.
*/
int d_num_procs;

/**
* @brief Dimension of the system on this processor.
*
* Equivalent to d_svd->getDim().
*/
const int d_dim;
};

}
Expand Down
93 changes: 60 additions & 33 deletions lib/linalg/BasisReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@

#include "BasisReader.h"
#include "utils/HDFDatabase.h"
#include "utils/CSVDatabase.h"
#include "utils/HDFDatabaseMPIO.h"
#include "Matrix.h"
#include "Vector.h"
#include "mpi.h"
#include "utils/mpi_utils.h"

namespace CAROM {

BasisReader::BasisReader(
const std::string& base_file_name,
Database::formats db_format) :
Database::formats db_format,
const int dim) :
d_dim(dim),
full_file_name(""),
base_file_name_(base_file_name)
base_file_name_(base_file_name),
d_format(db_format)
{
CAROM_ASSERT(!base_file_name.empty());

Expand All @@ -37,17 +41,29 @@ BasisReader::BasisReader(
rank = 0;
}

char tmp[100];
sprintf(tmp, ".%06d", rank);
full_file_name = base_file_name + tmp;
if (db_format == Database::HDF5) {
full_file_name = base_file_name;

// Enforce hdf data format.
if (d_format == Database::HDF5)
{
d_database = new HDFDatabase();
}
else if (db_format == Database::CSV) {
d_database = new CSVDatabase();
else if (d_format == Database::HDF5_MPIO)
{
/*
For MPIO case, local dimension needs to be specified.
We allow 0 local dimension. (global dimension still needs to be positive)
*/
std::vector<int> tmp;
d_global_dim = get_global_offsets(d_dim, tmp, MPI_COMM_WORLD);
CAROM_VERIFY(d_dim >= 0);
CAROM_VERIFY(d_global_dim > 0);
d_database = new HDFDatabaseMPIO();
}
else
CAROM_ERROR("BasisWriter only supports HDF5/HDF5_MPIO data format!\n");

d_database->open(full_file_name, "r");
d_database->open_parallel(full_file_name, "r", MPI_COMM_WORLD);
}

BasisReader::~BasisReader()
Expand All @@ -64,9 +80,9 @@ BasisReader::getSpatialBasis()

Matrix* spatial_basis_vectors = new Matrix(num_rows, num_cols, true);

d_database->getDoubleArray("spatial_basis",
&spatial_basis_vectors->item(0, 0),
num_rows*num_cols);
d_database->getDoubleArray_parallel("spatial_basis",
&spatial_basis_vectors->item(0, 0),
num_rows*num_cols);
return spatial_basis_vectors;
}

Expand All @@ -92,12 +108,12 @@ BasisReader::getSpatialBasis(

Matrix* spatial_basis_vectors = new Matrix(num_rows, num_cols_to_read, true);
sprintf(tmp, "spatial_basis");
d_database->getDoubleArray(tmp,
&spatial_basis_vectors->item(0, 0),
num_rows*num_cols_to_read,
start_col - 1,
num_cols_to_read,
num_cols);
d_database->getDoubleArray_parallel(tmp,
&spatial_basis_vectors->item(0, 0),
num_rows*num_cols_to_read,
start_col - 1,
num_cols_to_read,
num_cols);
return spatial_basis_vectors;
}

Expand Down Expand Up @@ -135,7 +151,7 @@ BasisReader::getTemporalBasis()
int num_cols = getNumSamples("temporal_basis");

char tmp[100];
Matrix* temporal_basis_vectors = new Matrix(num_rows, num_cols, true);
Matrix* temporal_basis_vectors = new Matrix(num_rows, num_cols, false);
sprintf(tmp, "temporal_basis");
d_database->getDoubleArray(tmp,
&temporal_basis_vectors->item(0, 0),
Expand Down Expand Up @@ -163,7 +179,7 @@ BasisReader::getTemporalBasis(
CAROM_VERIFY(start_col <= end_col && end_col <= num_cols);
int num_cols_to_read = end_col - start_col + 1;

Matrix* temporal_basis_vectors = new Matrix(num_rows, num_cols_to_read, true);
Matrix* temporal_basis_vectors = new Matrix(num_rows, num_cols_to_read, false);
sprintf(tmp, "temporal_basis");
d_database->getDoubleArray(tmp,
&temporal_basis_vectors->item(0, 0),
Expand Down Expand Up @@ -268,7 +284,18 @@ BasisReader::getDim(
"temporal_basis_num_rows");

d_database->getInteger(tmp, num_rows);
return num_rows;
/* only basis and snapshot are stored as distributed matrices */
if ((kind != "temporal_basis") && (d_format == Database::HDF5_MPIO))
{
/*
for MPIO database, return specified local dimension.
only checks the global dimension match.
*/
CAROM_VERIFY(d_global_dim == num_rows);
return d_dim;
}
else
return num_rows;
}

int
Expand Down Expand Up @@ -298,11 +325,11 @@ BasisReader::getSnapshotMatrix()
int num_cols = getNumSamples("snapshot");

char tmp[100];
Matrix* snapshots = new Matrix(num_rows, num_cols, false);
Matrix* snapshots = new Matrix(num_rows, num_cols, true);
sprintf(tmp, "snapshot_matrix");
d_database->getDoubleArray(tmp,
&snapshots->item(0, 0),
num_rows*num_cols);
d_database->getDoubleArray_parallel(tmp,
&snapshots->item(0, 0),
num_rows*num_cols);
return snapshots;
}

Expand All @@ -326,14 +353,14 @@ BasisReader::getSnapshotMatrix(
int num_cols_to_read = end_col - start_col + 1;

char tmp[100];
Matrix* snapshots = new Matrix(num_rows, num_cols_to_read, false);
Matrix* snapshots = new Matrix(num_rows, num_cols_to_read, true);
sprintf(tmp, "snapshot_matrix");
d_database->getDoubleArray(tmp,
&snapshots->item(0, 0),
num_rows*num_cols_to_read,
start_col - 1,
num_cols_to_read,
num_cols);
d_database->getDoubleArray_parallel(tmp,
&snapshots->item(0, 0),
num_rows*num_cols_to_read,
start_col - 1,
num_cols_to_read,
num_cols);
return snapshots;
}
}
29 changes: 28 additions & 1 deletion lib/linalg/BasisReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ class BasisReader {
* @param[in] db_format Format of the file to read.
* One of the implemented file formats defined in
* Database.
* @param[in] dim Dimension of the basis that will be read from a file.
* If negative, will use the dimension from the rank-specific local file.
*/
BasisReader(
const std::string& base_file_name,
Database::formats db_format = Database::HDF5);
Database::formats db_format = Database::HDF5,
const int dim = -1);

/**
* @brief Destructor.
Expand Down Expand Up @@ -197,6 +200,11 @@ class BasisReader {
*
* @brief Returns the dimension of the system on this processor.
*
* @param[in] kind The target matrix of which dimension (row) is returned.
* "basis" - local dimension of spatial basis
* "snapshot" - local dimension of snapshot matrix
* "temporal_basis" - global dimension of temporal basis
*
* @return The dimension of the system on this processor.
*/
int
Expand Down Expand Up @@ -277,6 +285,11 @@ class BasisReader {
*/
Database* d_database;

/**
* @brief The database being read from.
*/
Database::formats d_format;

/**
* @brief Base file name stored for consistency between reading and writing.
*/
Expand All @@ -286,6 +299,20 @@ class BasisReader {
* @brief Full file name of database including rank.
*/
std::string full_file_name;

/**
* @brief Dimension of the basis on this processor.
*
* If negative, use the dimension from the rank-specific local file.
*/
const int d_dim;

/**
* @brief Dimension of the basis on this processor.
*
* If negative, use the dimension from the rank-specific local file.
*/
int d_global_dim;
};

}
Expand Down
Loading
Loading