-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12964 from tjhei/mpi_create_big_datatype
Utilities::MPI::create_mpi_data_type_n_bytes
- Loading branch information
Showing
5 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
New: Utilities::MPI::create_mpi_data_type_n_bytes() helps with large MPI communication and IO. | ||
<br> | ||
(Timo Heister, 2021/11/17) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// --------------------------------------------------------------------- | ||
// | ||
// Copyright (C) 2021 by the deal.II authors | ||
// | ||
// This file is part of the deal.II library. | ||
// | ||
// The deal.II library is free software; you can use it, redistribute | ||
// it, and/or modify it under the terms of the GNU Lesser General | ||
// Public License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// The full text of the license can be found in the file LICENSE.md at | ||
// the top level directory of deal.II. | ||
// | ||
// --------------------------------------------------------------------- | ||
|
||
|
||
// Test Utilities::MPI::create_mpi_data_type_n_bytes | ||
|
||
// To not require a lot of memory, we run this test with smaller | ||
// size. Change this bool to test the real 64bit size communication: | ||
const bool run_big = false; | ||
|
||
#include <deal.II/base/mpi.h> | ||
|
||
#include "../tests.h" | ||
|
||
using namespace dealii; | ||
|
||
void | ||
test_data_type(const std::uint64_t n_bytes) | ||
{ | ||
MPI_Datatype bigtype = Utilities::MPI::create_mpi_data_type_n_bytes(n_bytes); | ||
|
||
deallog << "checking size " << n_bytes << ":"; | ||
|
||
int size32; | ||
int ierr = MPI_Type_size(bigtype, &size32); | ||
AssertThrowMPI(ierr); | ||
|
||
if (size32 == MPI_UNDEFINED) | ||
deallog << " size32=" | ||
<< "UNDEFINED (too big)"; | ||
else | ||
deallog << " size32=" << size32; | ||
|
||
#if DEAL_II_MPI_VERSION_GTE(3, 0) | ||
MPI_Count size64; | ||
ierr = MPI_Type_size_x(bigtype, &size64); | ||
AssertThrowMPI(ierr); | ||
|
||
deallog << " size64=" << size64; | ||
#endif | ||
|
||
deallog << std::endl; | ||
|
||
MPI_Type_free(&bigtype); | ||
} | ||
|
||
void | ||
test_send_recv(MPI_Comm comm) | ||
{ | ||
unsigned int myid = Utilities::MPI::this_mpi_process(comm); | ||
const std::uint64_t n_bytes = (run_big) ? ((1ULL << 31) + 37) : (37ULL); | ||
|
||
if (myid == 0) | ||
{ | ||
std::vector<char> buffer(n_bytes, 'A'); | ||
buffer[n_bytes - 1] = 'B'; | ||
MPI_Datatype bigtype = | ||
Utilities::MPI::create_mpi_data_type_n_bytes(buffer.size()); | ||
int ierr = | ||
MPI_Send(buffer.data(), 1, bigtype, 1 /* dest */, 0 /* tag */, comm); | ||
AssertThrowMPI(ierr); | ||
ierr = MPI_Type_free(&bigtype); | ||
AssertThrowMPI(ierr); | ||
} | ||
else if (myid == 1) | ||
{ | ||
std::vector<char> buffer(n_bytes, '?'); | ||
MPI_Datatype bigtype = | ||
Utilities::MPI::create_mpi_data_type_n_bytes(buffer.size()); | ||
int ierr = MPI_Recv(buffer.data(), | ||
1, | ||
bigtype, | ||
0 /* src */, | ||
0 /* tag */, | ||
comm, | ||
MPI_STATUS_IGNORE); | ||
AssertThrowMPI(ierr); | ||
ierr = MPI_Type_free(&bigtype); | ||
AssertThrowMPI(ierr); | ||
|
||
AssertThrow(buffer[0] == 'A', ExcInternalError()); | ||
AssertThrow(buffer[n_bytes - 1] == 'B', ExcInternalError()); | ||
} | ||
deallog << "send_recv: OK" << std::endl; | ||
} | ||
|
||
int | ||
main(int argc, char *argv[]) | ||
{ | ||
Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); | ||
MPILogInitAll all; | ||
|
||
test_data_type(0); | ||
test_data_type(1); | ||
test_data_type(1ULL << 30); | ||
test_data_type(1ULL << 31); | ||
test_data_type(1ULL << 32); | ||
test_data_type(1ULL << 33); | ||
test_data_type(1ULL << 55); | ||
test_data_type(58493729485ULL); | ||
|
||
test_send_recv(MPI_COMM_WORLD); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
DEAL:0::checking size 0: size32=0 size64=0 | ||
DEAL:0::checking size 1: size32=1 size64=1 | ||
DEAL:0::checking size 1073741824: size32=1073741824 size64=1073741824 | ||
DEAL:0::checking size 2147483648: size32=UNDEFINED (too big) size64=2147483648 | ||
DEAL:0::checking size 4294967296: size32=UNDEFINED (too big) size64=4294967296 | ||
DEAL:0::checking size 8589934592: size32=UNDEFINED (too big) size64=8589934592 | ||
DEAL:0::checking size 36028797018963968: size32=UNDEFINED (too big) size64=36028797018963968 | ||
DEAL:0::checking size 58493729485: size32=UNDEFINED (too big) size64=58493729485 | ||
DEAL:0::send_recv: OK | ||
|
||
DEAL:1::checking size 0: size32=0 size64=0 | ||
DEAL:1::checking size 1: size32=1 size64=1 | ||
DEAL:1::checking size 1073741824: size32=1073741824 size64=1073741824 | ||
DEAL:1::checking size 2147483648: size32=UNDEFINED (too big) size64=2147483648 | ||
DEAL:1::checking size 4294967296: size32=UNDEFINED (too big) size64=4294967296 | ||
DEAL:1::checking size 8589934592: size32=UNDEFINED (too big) size64=8589934592 | ||
DEAL:1::checking size 36028797018963968: size32=UNDEFINED (too big) size64=36028797018963968 | ||
DEAL:1::checking size 58493729485: size32=UNDEFINED (too big) size64=58493729485 | ||
DEAL:1::send_recv: OK | ||
|