Skip to content

Commit

Permalink
Add C++ dispatch example
Browse files Browse the repository at this point in the history
  • Loading branch information
LourensVeen committed Sep 30, 2023
1 parent b68dd26 commit 39be340
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/source/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rd_implementations.ymmsl
benchmark_implementations.ymmsl
dispatch_implementations.ymmsl
run_*
4 changes: 3 additions & 1 deletion docs/source/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ endif


.PHONY: base
base: python rd_implementations.ymmsl benchmark_implementations.ymmsl
base: python rd_implementations.ymmsl benchmark_implementations.ymmsl dispatch_implementations.ymmsl



Expand Down Expand Up @@ -106,6 +106,7 @@ clean:
$(MAKE) -C python clean
rm -f rd_implementations.ymmsl
rm -f benchmark_implementations.ymmsl
rm -f dispatch_implementations.ymmsl
rm -rf run_*/


Expand All @@ -129,6 +130,7 @@ test_cpp: base cpp
$$(ls $$(ls -d run_checkpointing_reaction_diffusion_cpp* | tail -n1)/snapshots/*.ymmsl | head -n1)
. python/build/venv/bin/activate && muscle_manager --start-all rd_implementations.ymmsl rd_python_cpp.ymmsl rd_settings.ymmsl
. python/build/venv/bin/activate && muscle_manager --start-all rd_implementations.ymmsl rdmc_cpp.ymmsl rdmc_settings.ymmsl
. python/build/venv/bin/activate && muscle_manager --start-all dispatch_implementations.ymmsl dispatch_cpp.ymmsl

.PHONY: test_cpp_mpi
test_cpp_mpi: base cpp_mpi
Expand Down
31 changes: 31 additions & 0 deletions docs/source/examples/cpp/buffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "libmuscle/libmuscle.hpp"
#include "ymmsl/ymmsl.hpp"

#include "unistd.h"


using libmuscle::Data;
using libmuscle::Instance;
using libmuscle::Message;
using ymmsl::Operator;


int main(int argc, char * argv[]) {
Instance instance(argc, argv, {
{Operator::F_INIT, {"in"}},
{Operator::O_F, {"out"}}});

while (instance.reuse_instance()) {
// F_INIT
Message msg = instance.receive("in", Message(0.0, Data("Testing")));

// S
usleep(250000);

// O_F
instance.send("out", msg);
}

return 0;
}

4 changes: 3 additions & 1 deletion docs/source/examples/cpp/build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ MPI_CXXFLAGS := -std=c++14 -g $(shell pkg-config --cflags libmuscle_mpi ymmsl)
MPI_LDFLAGS := $(shell pkg-config --libs libmuscle_mpi ymmsl)


binaries := reaction diffusion mc_driver load_balancer checkpointing_reaction checkpointing_diffusion benchmark
binaries := reaction diffusion mc_driver load_balancer
binaries += checkpointing_reaction checkpointing_diffusion
binaries += benchmark buffer
mpi_binaries := reaction_mpi


Expand Down
34 changes: 34 additions & 0 deletions docs/source/examples/dispatch_cpp.ymmsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ymmsl_version: v0.1

model:
name: dispatch_cpp

components:
component1:
implementation: buffer_cpp
ports:
o_f: out

component2:
implementation: buffer_cpp
ports:
f_init: in
o_f: out

component3:
implementation: buffer_cpp
ports:
f_init: in

conduits:
component1.out: component2.in
component2.out: component3.in

resources:
component1:
threads: 1
component2:
threads: 1
component3:
threads: 1

8 changes: 8 additions & 0 deletions docs/source/examples/dispatch_implementations.ymmsl.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ymmsl_version: v0.1

implementations:
buffer_cpp:
env:
+LD_LIBRARY_PATH: :MUSCLE3_HOME/lib
executable: MUSCLE3_EXAMPLES/cpp/build/buffer

0 comments on commit 39be340

Please sign in to comment.