-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move print_result to header file, remove kamping:: after using namespace, add missing license header * Print rank, add function to print result on all PEs, take Communicator by reference * Add documentation
- Loading branch information
1 parent
a195106
commit 34ca36b
Showing
3 changed files
with
74 additions
and
33 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
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,41 @@ | ||
// This file is part of KaMPI.ng. | ||
// | ||
// Copyright 2022 The KaMPI.ng Authors | ||
// | ||
// KaMPI.ng is free software : you can 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 3 of the License, or (at your option) any later | ||
// version. KaMPI.ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | ||
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | ||
// for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License along with KaMPI.ng. If not, see | ||
// <https://www.gnu.org/licenses/>. | ||
|
||
#include <vector> | ||
|
||
#include "kamping/communicator.hpp" | ||
|
||
namespace kamping { | ||
/// @brief Print all elements in a container, prefixed with the rank of the current PE. | ||
/// @tparam T Type of the elements contained in the container. | ||
/// @param result The container whose elements are printed. | ||
/// @param comm KaMPI.ng communicator to get the rank of the PE. | ||
template <typename T> | ||
void print_result(std::vector<T> const& result, Communicator const& comm) { | ||
for (auto const& elem: result) { | ||
std::cout << "[PE " << comm.rank() << "] " << elem << "\n"; | ||
} | ||
std::cout << std::flush; | ||
} | ||
|
||
/// @brief Print all elements in a container only on the root PE. | ||
/// @tparam T Type of the elements contained in the container. | ||
/// @param result The container whose elements are printed on the root PE. | ||
/// @param comm KaMPI.ng communicator to determine which PE is the root PE. | ||
template <typename T> | ||
void print_result_on_root(std::vector<T> const& result, Communicator const& comm) { | ||
if (comm.is_root()) { | ||
print_result(result, comm); | ||
} | ||
} | ||
} // namespace kamping |
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