Skip to content

Commit

Permalink
Merge branch 'pr-parallel-serialize' into pr-fix-cc2
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/madness/world/worlddc.h
  • Loading branch information
fbischoff committed Aug 16, 2024
2 parents e74d000 + 0e8faf9 commit 63ef10b
Show file tree
Hide file tree
Showing 6 changed files with 903 additions and 576 deletions.
2 changes: 1 addition & 1 deletion src/madness/tensor/srconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ namespace madness {
public:
/// return the number of physical dimensions
int dim_per_vector(int idim) const {
MADNESS_ASSERT(vector_.size()>idim);
MADNESS_ASSERT(vector_.size()>size_t(idim));
return vector_[idim].ndim()-1; // remove dimension for the rank
}

Expand Down
34 changes: 17 additions & 17 deletions src/madness/world/parallel_archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,31 @@ namespace madness {

/// \return The process doing I/O for this node.
ProcessID my_io_node() const {
MADNESS_ASSERT(world);
MADNESS_CHECK(world);
return io_node(world->rank());
}

/// Returns the number of I/O clients for this node, including self (zero if not an I/O node).

/// \return The number of I/O clients for this node, including self (zero if not an I/O node).
int num_io_clients() const {
MADNESS_ASSERT(world);
MADNESS_CHECK(world);
return nclient;
}

/// Returns true if this node is doing physical I/O.

/// \return True if this node is doing physical I/O.
bool is_io_node() const {
MADNESS_ASSERT(world);
MADNESS_CHECK(world);
return world->rank() == my_io_node();
}

/// Returns a pointer to the world.

/// \return A pointer to the world.
World* get_world() const {
MADNESS_ASSERT(world);
MADNESS_CHECK(world);
return world;
}

Expand Down Expand Up @@ -166,12 +166,12 @@ namespace madness {
if (nio > maxio) nio = maxio; // Sanity?
if (nio > world.size()) nio = world.size();

MADNESS_ASSERT(filename);
MADNESS_ASSERT(strlen(filename)-1<sizeof(fname));
MADNESS_CHECK(filename);
MADNESS_CHECK(strlen(filename)-1<sizeof(fname));
strcpy(fname,filename); // Save the filename for later
constexpr std::size_t bufsize=256;
constexpr std::size_t bufsize=512;
char buf[bufsize];
MADNESS_ASSERT(strlen(filename)+7 <= sizeof(buf));
MADNESS_CHECK(strlen(filename)+7 <= sizeof(buf));
snprintf(buf, bufsize, "%s.%5.5d", filename, world.rank());

// if file doesn't exist we have a race condition if this code is handled by a try/catch block
Expand All @@ -183,7 +183,7 @@ namespace madness {
if (world.rank() == 0) {
ar.open(buf);
ar & nio; // read/write nio from/to the archive
MADNESS_ASSERT(nio <= world.size());
MADNESS_CHECK(nio <= world.size());
}

// Ensure all agree on value of nio that may also have changed if reading
Expand Down Expand Up @@ -222,9 +222,9 @@ namespace madness {
typename std::enable_if_t<std::is_same<X,BinaryFstreamInputArchive>::value || std::is_same<X,BinaryFstreamOutputArchive>::value,
bool>
exists(World& world, const char* filename) {
constexpr std::size_t bufsize=256;
constexpr std::size_t bufsize=512;
char buf[bufsize];
MADNESS_ASSERT(strlen(filename)+7 <= sizeof(buf));
MADNESS_CHECK(strlen(filename)+7 <= sizeof(buf));
snprintf(buf,bufsize, "%s.%5.5d", filename, world.rank());
bool status;
if (world.rank() == 0)
Expand All @@ -237,7 +237,7 @@ namespace madness {

/// Closes the parallel archive.
void close() {
MADNESS_ASSERT(world);
MADNESS_CHECK(world);
if (is_io_node()) ar.close();
}

Expand All @@ -246,8 +246,8 @@ namespace madness {
/// \throw MadnessException If not an I/O node.
/// \return A reference to the local archive.
Archive& local_archive() const {
MADNESS_ASSERT(world);
MADNESS_ASSERT(is_io_node());
MADNESS_CHECK(world);
MADNESS_CHECK(is_io_node());
return ar;
}

Expand All @@ -273,9 +273,9 @@ namespace madness {
void>
remove(World& world, const char* filename) {
if (world.rank() == 0) {
constexpr std::size_t bufsize=268;
constexpr std::size_t bufsize=512;
char buf[bufsize];
MADNESS_ASSERT(strlen(filename)+7 <= sizeof(buf));
MADNESS_CHECK(strlen(filename)+7 <= sizeof(buf));
for (ProcessID p=0; p<world.size(); ++p) {
snprintf(buf,bufsize, "%s.%5.5d", filename, p);
if (::remove(buf)) break;
Expand All @@ -285,7 +285,7 @@ namespace madness {

/// Removes the files associated with the current archive.
void remove() {
MADNESS_ASSERT(world);
MADNESS_CHECK(world);
remove(*world, fname);
}

Expand Down
44 changes: 43 additions & 1 deletion src/madness/world/parallel_dc_archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,57 @@ namespace madness {
};


/// Implementation of functions for storing the pre/postamble in ContainerRecord archives.

/// \attention No type checking over Vector buffers, for efficiency.
/// \tparam T The data type.
template <class T>
struct ArchivePrePostImpl<ContainerRecordOutputArchive,T> {
/// Store the preamble.

/// \param[in] ar The archive.
static void preamble_store(const ContainerRecordOutputArchive& ar) {};

/// Store the postamble.

/// \param[in] ar The archive.
static inline void postamble_store(const ContainerRecordOutputArchive& ar) {};
};

/// Implementation of functions for loading the pre/postamble in ContainerRecord archives.

/// \attention No type checking over ContainerRecord buffers, for efficiency.
/// \tparam T The data type.
template <class T>
struct ArchivePrePostImpl<ContainerRecordInputArchive,T> {
/// Load the preamble.

/// \param[in] ar The archive.
static inline void preamble_load(const ContainerRecordInputArchive& ar) {};

/// Load the postamble.

/// \param[in] ar The archive.
static inline void postamble_load(const ContainerRecordInputArchive& ar) {};
};

// Forward storing to VectorOutputArchive
template <class keyT, class valueT>
struct ArchiveStoreImpl< ParallelOutputArchive<ContainerRecordOutputArchive>, WorldContainer<keyT,valueT> > {
static void store(const ParallelOutputArchive<ContainerRecordOutputArchive>& ar, const WorldContainer<keyT,valueT>& t) {
ParallelOutputArchive<VectorOutputArchive> par(*(ar.get_world()), ar.local_archive().get_archive());
std::vector<unsigned char> v;
VectorOutputArchive dummyar(v,0);
const int me = ar.get_world()->rank();

// Need to pass local archive by reference
ParallelOutputArchive<VectorOutputArchive> par(*(ar.get_world()), (me==0) ? ar.local_archive().get_archive() : dummyar);
par & t;

}
};



}


Expand Down
17 changes: 13 additions & 4 deletions src/madness/world/test_dc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,16 @@ void test_local(World& world) {

void test_florian(World& world) {
WorldContainer<Key,LargeNode> c(world);
long nlarge=200000;

long nlarge=20000;
// get nlarge variable from the environment and convert it into long
char* nlarge_env = getenv("NLARGE");
if (nlarge_env) {
nlarge = atol(nlarge_env);
}
if (world.rank()==0) print("size of the container",nlarge);



if (world.rank() == 0) {
for (int i=0; i<nlarge; ++i) {
Expand All @@ -279,15 +288,15 @@ void test_florian(World& world) {
}
world.gop.fence();
double wall0=wall_time();
printf("starting at time %8.4f with %ld items\n",wall0,nlarge);
if (world.rank() == 0) printf("starting at time %8.4f with %ld items\n",wall0,nlarge);
std::vector<unsigned char> v;
{
archive::VectorOutputArchive var(v);
archive::ParallelOutputArchive ar(world,var);
ar & c;
}
double wall1=wall_time();
printf("ending at time %8.4f after %8.4fs\n",wall1,wall1-wall0);
if (world.rank() == 0) printf("ending at time %8.4f after %8.4fs\n",wall1,wall1-wall0);

WorldContainer<Key,LargeNode> c2(world);
{
Expand All @@ -303,7 +312,7 @@ void test_florian(World& world) {
}

world.gop.fence();
print("test_florian passed");
if (world.rank() == 0) print("test_florian passed");
}

int main(int argc, char** argv) {
Expand Down
34 changes: 34 additions & 0 deletions src/madness/world/vector_archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,40 @@ namespace madness {
void close() {}
};

/// Implementation of functions for storing the pre/postamble in Vector archives.

/// \attention No type checking over Vector buffers, for efficiency.
/// \tparam T The data type.
template <class T>
struct ArchivePrePostImpl<VectorOutputArchive,T> {
/// Store the preamble.

/// \param[in] ar The archive.
static void preamble_store(const VectorOutputArchive& ar) {};

/// Store the postamble.

/// \param[in] ar The archive.
static inline void postamble_store(const VectorOutputArchive& ar) {};
};

/// Implementation of functions for loading the pre/postamble in Vector archives.

/// \attention No type checking over Vector buffers, for efficiency.
/// \tparam T The data type.
template <class T>
struct ArchivePrePostImpl<VectorInputArchive,T> {
/// Load the preamble.

/// \param[in] ar The archive.
static inline void preamble_load(const VectorInputArchive& ar) {};

/// Load the postamble.

/// \param[in] ar The archive.
static inline void postamble_load(const VectorInputArchive& ar) {};
};

/// @}
}
}
Expand Down
Loading

0 comments on commit 63ef10b

Please sign in to comment.