43#ifndef MADNESS_WORLD_TEST_RMI_HUGE_H__INCLUDED
44#define MADNESS_WORLD_TEST_RMI_HUGE_H__INCLUDED
62using wordT = std::uint64_t;
65inline wordT pattern(std::size_t i, std::uint64_t seed) {
66 return (i + seed) * 0x9E3779B97F4A7C15ull;
70std::vector<wordT> make_message(std::size_t nbyte, std::uint64_t seed) {
71 std::vector<wordT>
v((nbyte +
sizeof(wordT) - 1) /
sizeof(wordT));
72 for (std::size_t i = 0; i <
v.size(); ++i)
v[i] = pattern(i, seed);
78std::size_t count_errors(
const std::vector<wordT>&
v, std::size_t nbyte, std::uint64_t seed) {
79 if (
v.size() != (nbyte +
sizeof(wordT) - 1) /
sizeof(wordT))
return std::size_t(-1);
81 for (std::size_t i = 0; i <
v.size(); ++i) nerr += (
v[i] != pattern(i, seed));
86bool send_and_check(
World& world,
const std::vector<std::size_t>& sizes,
const std::string& what) {
88 std::vector<Future<std::size_t>> results;
89 for (std::size_t
k = 0;
k < sizes.size(); ++
k) {
90 const std::uint64_t seed = 1000 * world.
rank() +
k;
91 results.push_back(world.
taskq.
add(dest, &count_errors, make_message(sizes[
k], seed), sizes[
k], seed));
95 for (std::size_t
k = 0;
k < sizes.size(); ++
k) {
96 const std::size_t nerr = results[
k].get();
99 std::cout <<
"rank " << world.
rank() <<
": " << what <<
": message of " << sizes[
k]
100 <<
" bytes arrived with " << (nerr == std::size_t(-1) ?
"the wrong size" :
"wrong contents")
106 if (world.
rank() == 0) std::cout << what <<
": " << (all_ok ?
"ok" :
"FAILED") << std::endl;
113 if (!
bc.derived() ||
bc.count() != 1)
return false;
115 MPI_Aint lb = -1, extent = -1, true_lb = -1, true_extent = -1;
117 MPI_Type_get_true_extent(
bc.datatype(), &true_lb, &true_extent);
118 return lb == 0 && true_lb == 0 &&
static_cast<std::size_t
>(extent) == n &&
119 static_cast<std::size_t
>(true_extent) == n;
124bool test_byte_count() {
125 const std::size_t int_max =
static_cast<std::size_t
>(std::numeric_limits<int>::max());
133 ok =
ok && !
bc.derived() &&
bc.count() == std::numeric_limits<int>::max();
135 for (std::size_t n : {std::size_t(1001), std::size_t(2000), std::size_t(123457)}) {
137 ok =
ok && describes(
bc, n);
139 for (std::size_t n : {int_max + 1, 2 * int_max, 2 * int_max + 1, (std::size_t(1) << 31) + (std::size_t(1) << 20) + 7,
140 std::size_t(5) << 32, (std::size_t(1) << 40) + 3}) {
142 ok =
ok && describes(
bc, n);
150int main(
int argc,
char** argv) {
154#ifdef MADNESS_TEST_RMI_HUGE_LARGE
155 if (world.
size() == 1) {
156 std::cout <<
"a message of more than INT_MAX bytes: skipped, needs 2 ranks" << std::endl;
163 std::size_t n = (std::size_t(1) << 31) + (std::size_t(1) << 20) + 7;
164 if (
const char* env = std::getenv(
"MAD_TEST_RMI_HUGE_BYTES")) n = std::strtoull(env,
nullptr, 10);
165 ok = send_and_check(world, world.
rank() == 0 ? std::vector<std::size_t>{n} : std::vector<std::size_t>{},
166 std::string(
"a message of more than INT_MAX bytes") +
171 ok = send_and_check(world, world.
rank() == 0 ? std::vector<std::size_t>{n} : std::vector<std::size_t>{},
172 "a message of more than INT_MAX bytes (derived datatype)") &&
ok;
176 const std::size_t MiB = std::size_t(1) << 20;
182 if (world.
rank() == 0) {
183 const bool bc_ok = test_byte_count();
184 std::cout <<
"ByteCount: " << (bc_ok ?
"ok" :
"FAILED") << std::endl;
189 ok = send_and_check(world, {huge + 12345},
"a plain count") &&
ok;
193 std::vector<bool> large_count_choices{
false};
195 for (
const bool large_count : large_count_choices) {
197 const std::string how = large_count ?
" (large count)" :
" (derived datatype)";
199 ok = send_and_check(world, {huge + 12345},
"one message, not a whole number of chunks" + how) &&
ok;
203 ok = send_and_check(world, {huge / 8},
"one message, a whole number of chunks" + how) &&
ok;
205 ok = send_and_check(world, {huge + 1, 2 * huge + 77, huge + MiB, 100, huge + 5},
"several at once" + how) &&
ok;
210 ok = send_and_check(world, {huge + 12345, 2 * huge + 77},
"large count on one end, derived datatype on the other") &&
ok;
This header should include pretty much everything needed for the parallel runtime.
The (count, datatype) pair that describes a buffer of bytes to MPI.
Definition safempi.h:531
static bool use_large_count()
Definition safempi.h:619
static void set_use_large_count(bool flag)
Sets use_large_count().
Definition safempi.h:626
static constexpr bool have_large_count()
Definition safempi.h:608
static void set_max_plain_count(std::size_t n)
Sets max_plain_count().
Definition safempi.h:601
static std::size_t max_msg_len()
Returns the size of recv buffers, in bytes.
Definition worldrmi.h:329
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:177
void logic_and(T *buf, size_t nelem)
Definition worldgop.h:940
void add(TaskInterface *t)
Add a new local task, taking ownership of the pointer.
Definition world_task_queue.h:466
A parallel world class.
Definition world.h:134
WorldTaskQueue & taskq
Task queue.
Definition world.h:215
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition world.h:344
ProcessID size() const
Returns the number of processes in this World (same as MPI_Comm_size()).
Definition world.h:354
WorldGopInterface & gop
Global operations.
Definition world.h:216
static const double v
Definition hatom_sf_dirac.cc:20
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
std::optional< BoundaryConditions< NDIM > > FunctionDefaults< NDIM >::bc
Definition mraimpl.h:3890
void finalize()
Call this once at the very end of your main program instead of MPI_Finalize().
Definition world.cc:246
World & initialize(int &argc, char **&argv, bool quiet)
Definition world.cc:153
static const long k
Definition rk.cc:44
Serializes calls to MPI in case it does not support THREAD_MULTIPLE.
std::ptrdiff_t MPI_Aint
Definition stubmpi.h:32
int MPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint *lb, MPI_Aint *extent)
Definition stubmpi.h:99
#define MPI_BYTE
Definition stubmpi.h:78
std::string ok(const bool b)
Definition test6.cc:48
int main()
Definition test_workflow_builders.cpp:14
int ProcessID
Used to clearly identify process number/rank.
Definition worldtypes.h:43