Skip to content

Commit 4d79bac

Browse files
committed
Increase version to 2.0.0 and update docs
- move examples to dedicated folder and make sure they compile - remove old docs about laziness
1 parent db6f15b commit 4d79bac

File tree

16 files changed

+176
-231
lines changed

16 files changed

+176
-231
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cmake_policy(VERSION ${CMAKE_VERSION})
1919

2020
# ############
2121
# Define Project
22-
project(mpi VERSION 1.3.0 LANGUAGES CXX)
22+
project(mpi VERSION 2.0.0 LANGUAGES CXX)
2323
get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY)
2424

2525
# Get the git hash & print status

doc/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ add_custom_target(doxygen ALL
2525
VERBATIM
2626
)
2727

28+
# Compile example codes
29+
add_subdirectory(examples)
30+
2831
# ############
2932
# Install
3033
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ COMPONENT documentation DESTINATION share/doc/${PROJECT_NAME}

doc/documentation.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ If you are looking for a specific function, class, etc., try using the search ba
2828
Besides storing the `MPI_Group` object, it also provides some convient functions for getting the size of the
2929
group, the rank of the current process or for splitting the group based on include rules.
3030

31-
It further contains the convenient function mpi::is_initialized and the static boolean mpi::has_env.
31+
It further contains the convenient functions mpi::is_initialized and mpi::is_finalized and the static boolean
32+
mpi::has_env.
3233

3334
## MPI datatypes and operations
3435

3536
@ref mpi_types_ops map various C++ datatypes to MPI datatypes and help the user with registering their own datatypes to
3637
be used in MPI communications.
38+
3739
Furthermore, it offers tools to simplify the creation of custom MPI operations usually required in `MPI_Reduce` or
3840
`MPI_Accumulate` functions.
3941

@@ -71,13 +73,6 @@ Another use-case of @ref mpi_osc_shm is the shared memory aspect by which
7173
MPI applications can reduce their memory requirements through the deduplication
7274
of replicated data between MPI ranks that are executed on the same SMP node.
7375

74-
## Lazy MPI communication
75-
76-
@ref mpi_lazy can be used to provied collective MPI communication for lazy expression types.
77-
Most users probably won't need to use this functionality directly.
78-
79-
We refer the interested reader to [TRIQS/nda](https://triqs.github.io/nda/latest/group__av__mpi.html) for more details.
80-
8176
## Event handling
8277

8378
@ref event_handling provides the mpi::monitor class which can be used to communicate and handle events across multiple

doc/ex1.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,7 @@
44

55
In this example, we show how to implement the standard `Hello world` program using **mpi**.
66

7-
```cpp
8-
#include <mpi/mpi.hpp>
9-
#include <iostream>
10-
11-
int main(int argc, char *argv[]) {
12-
// initialize MPI environment and communicator
13-
mpi::environment env(argc, argv);
14-
mpi::communicator world;
15-
16-
// get rank and greet world
17-
int rank = world.rank();
18-
std::cout << "Hello from processor " << rank << "\n";
19-
}
20-
```
7+
@include ex1.cpp
218

229
Output (depends on the number of processes and the order is arbitrary):
2310

doc/ex2.md

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,7 @@
44

55
In this example, we show how to use the mpi::monitor class to communicate and process errors across a communicator.
66

7-
```cpp
8-
#include <mpi/mpi.hpp>
9-
#include <mpi/monitor.hpp>
10-
#include <iostream>
11-
12-
int main(int argc, char *argv[]) {
13-
// initialize MPI environment
14-
mpi::environment env(argc, argv);
15-
mpi::communicator world;
16-
17-
// initialize monitor
18-
mpi::monitor monitor(world);
19-
20-
// in case an event has occurred, print some info and return true
21-
auto stop = [&monitor, world](int i) {
22-
bool res = false;
23-
if (monitor.event_on_any_rank()) {
24-
std::cerr << "Processor " << world.rank() << ": After " << i << " steps an event has been communicated.\n";
25-
res = true;
26-
}
27-
return res;
28-
};
29-
30-
// loop as long as no event has occurred
31-
int event_rank = 3;
32-
for (int i = 0; i < 1000000; ++i) {
33-
// report a local event on the event_rank
34-
if (world.rank() == event_rank) {
35-
std::cerr << "Processor " << event_rank << ": Local event reported.\n";
36-
monitor.report_local_event();
37-
}
38-
39-
// should we stop the loop?
40-
if (stop(i)) break;
41-
}
42-
43-
// check if all processes finished the loop
44-
if (world.rank() == 0) {
45-
if (monitor.event_on_any_rank()) {
46-
std::cout << "Oh no! An event occurred somewhere and the loop has not been finished on all processes.\n";
47-
} else {
48-
std::cout << "No worries, all processes have finished the loop.\n";
49-
}
50-
}
51-
}
52-
```
7+
@include ex2.cpp
538

549
Output (running with `-n 12`):
5510

doc/ex3.md

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,11 @@
22

33
[TOC]
44

5-
In this example, we show how to register a new MPI datatype and how to use mpi::map_C_function and mpi::map_add to
6-
define MPI operations for it.
5+
In this example, we show
6+
- how to register a new MPI datatype by providing a `tie_data` function for our C++ type and
7+
- how to use mpi::map_C_function and mpi::map_add to define MPI operations for it.
78

8-
```cpp
9-
#include <mpi/mpi.hpp>
10-
#include <iostream>
11-
12-
// define a custom complex type
13-
struct my_complex {
14-
double real;
15-
double imag;
16-
};
17-
18-
// define an addition for my_complex
19-
inline my_complex operator+(const my_complex& z1, const my_complex& z2) {
20-
return { z1.real + z2.real, z1.imag + z2.imag };
21-
}
22-
23-
// define a tie_data function for my_complex to make it MPI compatible
24-
inline auto tie_data(const my_complex& z) {
25-
return std::tie(z.real, z.imag);
26-
}
27-
28-
int main(int argc, char *argv[]) {
29-
// initialize MPI environment
30-
mpi::environment env(argc, argv);
31-
mpi::communicator world;
32-
33-
// create complex number z
34-
my_complex z = { world.rank() + 1.0, static_cast<double>(world.rank()) };
35-
36-
// sum z over all processes
37-
auto sum = mpi::reduce(z, world, 0, false, mpi::map_add<my_complex>());
38-
39-
// define a product for my_complex
40-
auto my_product = [](const my_complex& z1, const my_complex& z2) {
41-
return my_complex { z1.real * z2.real - z1.imag * z2.imag, z1.real * z2.imag + z1.imag * z2.real };
42-
};
43-
44-
// multiply z over all processes
45-
auto product = mpi::reduce(z, world, 0, false, mpi::map_C_function<my_complex, my_product>());
46-
47-
// print result
48-
if (world.rank() == 0) {
49-
std::cout << "sum = (" << sum.real << ", " << sum.imag << ")\n";
50-
std::cout << "product = (" << product.real << ", " << product.imag << ")\n";
51-
}
52-
}
53-
```
9+
@include ex3.cpp
5410

5511
Output (running with `-n 5`):
5612

doc/ex4.md

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,7 @@
44

55
In this example, we show how to write a specialized `mpi_reduce_into` for a custom type.
66

7-
```cpp
8-
#include <mpi/mpi.hpp>
9-
#include <iostream>
10-
#include <vector>
11-
12-
// Custom type.
13-
class foo {
14-
public:
15-
// Constructor.
16-
foo(int x = 5) : x_(x) {}
17-
18-
// Get the value stored in the class.
19-
int x() const { return x_; }
20-
21-
// Specialization of mpi_reduce_into for the custom type.
22-
friend void mpi_reduce_into(foo const &f_in, foo &f_out, mpi::communicator c = {}, int root = 0, bool all = false, MPI_Op op = MPI_SUM) {
23-
mpi::reduce_into(f_in.x_, f_out.x_, c, root, all, op);
24-
}
25-
26-
private:
27-
int x_;
28-
};
29-
30-
int main(int argc, char *argv[]) {
31-
// initialize MPI environment
32-
mpi::environment env(argc, argv);
33-
mpi::communicator world;
34-
35-
// create a vector of foo objects
36-
std::vector<foo> vec {foo{1}, foo{2}, foo{3}, foo{4}, foo{5}};
37-
38-
// reduce the vector of foo objects
39-
auto result = mpi::reduce(vec, world);
40-
41-
// print the result on rank 0
42-
if (world.rank() == 0) {
43-
std::cout << "Reduced vector: ";
44-
for (auto const &f : result) std::cout << f.x() << " ";
45-
std::cout << "\n";
46-
}
47-
}
48-
```
7+
@include ex4.cpp
498

509
Output (running with `-n 4`):
5110

doc/examples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
All examples have been compiled on a MacBook Pro with an Apple M2 Max chip and [open-mpi](https://www.open-mpi.org/)
1313
5.0.1.
14-
We further used clang 19.1.7 together with cmake 3.31.5.
14+
We further used clang 21.1.2 together with cmake 4.1.2.
1515

1616
Assuming that the actual example code is in a file `main.cpp`, the following generic `CMakeLists.txt` should work for
1717
all examples:
@@ -31,7 +31,7 @@ include (FetchContent)
3131
FetchContent_Declare(
3232
mpi
3333
GIT_REPOSITORY https://github.com/TRIQS/mpi.git
34-
GIT_TAG 1.3.x
34+
GIT_TAG 2.0.x
3535
)
3636
FetchContent_MakeAvailable(mpi)
3737

doc/examples/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# List of all examples
2+
file(GLOB_RECURSE all_examples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
3+
4+
foreach(ex_src ${all_examples})
5+
get_filename_component(ex_name ${ex_src} NAME_WE)
6+
add_executable(${ex_name} ${ex_src})
7+
target_link_libraries(${ex_name} mpi::mpi_c)
8+
endforeach()

doc/examples/ex1.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <mpi/mpi.hpp>
2+
#include <iostream>
3+
4+
int main(int argc, char *argv[]) {
5+
// initialize MPI environment and communicator
6+
mpi::environment env(argc, argv);
7+
mpi::communicator world;
8+
9+
// get rank and greet world
10+
int rank = world.rank();
11+
std::cout << "Hello from processor " << rank << "\n";
12+
}

0 commit comments

Comments
 (0)