split_and_merge

Four models, A, B, C, & D, pass messages between them, splitting and joining variables in the messages between them. Model A receives input from a tab delimited table and sends two output variables which are split between models B & C according to the output_pattern: ‘scatter’ YAML parameter. The outputs from Models B & C are then merged and sent to model D according to the input_pattern: ‘gather’ YAML parameter. The output from model D is then sent to a table.

C Version

Model Code:

1#include <stdio.h>
2
3int modelA_function(float in_val, float* out_val1, float* out_val2) {
4  out_val1[0] = 2 * in_val;
5  out_val2[0] = 3 * in_val;
6  printf("modelA_function(%f) = (%f, %f)\n", in_val, *out_val1, *out_val2);
7  return 0;
8}
1#include <stdio.h>
2#include <math.h>
3
4float modelB_function(float in_val) {
5  float out_val = 3 * in_val;
6  printf("modelB_function(%f) = %f\n", in_val, out_val);
7  return out_val;
8}
1#include <stdio.h>
2#include <math.h>
3
4float modelC_function(float in_val) {
5  float out_val = 4 * in_val;
6  printf("modelC_function(%f) = %f\n", in_val, out_val);
7  return out_val;
8}
 1#include <stdio.h>
 2#include <math.h>
 3
 4int modelD_function(float in_val1, float in_val2, float* in_val1_copy, float* in_val2_copy, float* out_val) {
 5  in_val1_copy[0] = in_val1;
 6  in_val2_copy[0] = in_val2;
 7  out_val[0] = in_val1 + in_val2;
 8  printf("modelD_function(%f, %f) = %f\n", in_val1, in_val2, *out_val);
 9  return 0;
10}

Model YAML:

 1models:
 2  - name: c_modelA
 3    language: c
 4    args: ./src/split_and_merge_modelA.c
 5    function: modelA_function
 6    outputs:
 7      - name: c_modelA:output
 8        vars:
 9          - out_val1
10          - out_val2
11
12  - name: c_modelB
13    language: c
14    args: ./src/split_and_merge_modelB.c
15    function: modelB_function
16    outputs: c_modelB:output
17
18  - name: c_modelC
19    language: c
20    args: ./src/split_and_merge_modelC.c
21    function: modelC_function
22    outputs: c_modelC:output
23
24  - name: c_modelD
25    language: c
26    args: ./src/split_and_merge_modelD.c
27    function: modelD_function
28    outputs:
29      - name: c_modelD:output
30        vars:
31          - in_val1_copy
32          - in_val2_copy
33          - out_val
34
35connections:
36  - input: ./Input/input.txt
37    output: c_modelA:input
38    filetype: table
39  - input: c_modelA:output
40    outputs:
41      - c_modelB:input
42      - c_modelC:input
43    output_pattern: scatter
44  - inputs:
45      - c_modelB:output
46      - c_modelC:output
47    output: c_modelD:input
48    input_pattern: gather
49  - input: c_modelD:output
50    output: ./outputD.txt
51    filetype: table
52    field_units: g/s,g/s,g/s

C++ Version

Model Code:

1#include <iostream>
2
3int modelA_function(float in_val, float &out_val1, float &out_val2) {
4  out_val1 = 2 * in_val;
5  out_val2 = 3 * in_val;
6  std::cout << "modelA_function(" << in_val << ") = (" << out_val1 << ", " << out_val2 << ")" << std::endl;
7  return 0;
8}
1#include <iostream>
2#include <math.h>
3
4float modelB_function(float in_val) {
5  float out_val = 3 * in_val;
6  std::cout << "modelB_function(" << in_val << ") = " << out_val << std::endl;
7  return out_val;
8}
1#include <iostream>
2#include <math.h>
3
4float modelC_function(float in_val) {
5  float out_val = 4 * in_val;
6  std::cout << "modelC_function(" << in_val << ") = " << out_val << std::endl;
7  return out_val;
8}
 1#include <iostream>
 2#include <math.h>
 3
 4int modelD_function(float in_val1, float in_val2, float &in_val1_copy, float &in_val2_copy, float &out_val) {
 5  in_val1_copy = in_val1;
 6  in_val2_copy = in_val2;
 7  out_val = in_val1 + in_val2;
 8  std::cout << "modelD_function(" << in_val1 << ", " << in_val2 << ") = " << out_val << std::endl;
 9  return 0;
10}

Model YAML:

 1models:
 2  - name: cpp_modelA
 3    language: cpp
 4    args: ./src/split_and_merge_modelA.cpp
 5    function: modelA_function
 6    outputs: cpp_modelA:output
 7
 8  - name: cpp_modelB
 9    language: cpp
10    args: ./src/split_and_merge_modelB.cpp
11    function: modelB_function
12    outputs: cpp_modelB:output
13
14  - name: cpp_modelC
15    language: cpp
16    args: ./src/split_and_merge_modelC.cpp
17    function: modelC_function
18    outputs: cpp_modelC:output
19
20  - name: cpp_modelD
21    language: cpp
22    args: ./src/split_and_merge_modelD.cpp
23    function: modelD_function
24    outputs: cpp_modelD:output
25
26connections:
27  - input: ./Input/input.txt
28    output: cpp_modelA:input
29    filetype: table
30  - input: cpp_modelA:output
31    outputs:
32      - cpp_modelB:input
33      - cpp_modelC:input
34    output_pattern: scatter
35  - inputs:
36      - cpp_modelB:output
37      - cpp_modelC:output
38    output: cpp_modelD:input
39    input_pattern: gather
40  - input: cpp_modelD:output
41    output: ./outputD.txt
42    filetype: table
43    field_units: g/s,g/s,g/s

Fortran Version

Model Code:

1function modelA_function(in_val, out_val1, out_val2) result(out)
2  real(kind=8), intent(in) :: in_val
3  real(kind=8), intent(out) :: out_val1, out_val2
4  logical :: out
5  out = .true.
6  out_val1 = 2 * in_val
7  out_val2 = 3 * in_val
8  write(*, '("modelA_function(",F10.5,") = (",F10.5,", ",F10.5,")")') in_val, out_val1, out_val2
9end function modelA_function
1function modelB_function(in_val, out_val) result(out)
2  real(kind=8), intent(in) :: in_val
3  real(kind=8), intent(out) :: out_val
4  logical :: out
5  out = .true.
6  out_val = 3 * in_val
7  write(*, '("modelB_function(",F10.5,") = (",F10.5,")")') in_val, out_val
8end function modelB_function
1function modelC_function(in_val, out_val) result(out)
2  real(kind=8), intent(in) :: in_val
3  real(kind=8), intent(out) :: out_val
4  logical :: out
5  out = .true.
6  out_val = 4 * in_val
7  write(*, '("modelC_function(",F10.5,") = (",F10.5,")")') in_val, out_val
8end function modelC_function
 1function modelD_function(in_val1, in_val2, in_val1_copy, in_val2_copy, out_val) result(out)
 2  real(kind=8), intent(in) :: in_val1, in_val2
 3  real(kind=8), intent(out) :: in_val1_copy, in_val2_copy, out_val
 4  logical :: out
 5  out = .true.
 6  in_val1_copy = in_val1
 7  in_val2_copy = in_val2
 8  out_val = in_val1 + in_val2
 9  write(*, '("modelD_function(",F10.5,", ",F10.5,") = (",F10.5,")")') in_val1, in_val2, out_val
10end function modelD_function

Model YAML:

 1models:
 2  - name: fortran_modelA
 3    language: fortran
 4    args: ./src/split_and_merge_modelA.f90
 5    function: modelA_function
 6    outputs:
 7      - name: fortran_modelA:output
 8        vars:
 9          - out_val1
10          - out_val2
11
12  - name: fortran_modelB
13    language: fortran
14    args: ./src/split_and_merge_modelB.f90
15    function: modelB_function
16    outputs: fortran_modelB:output
17
18  - name: fortran_modelC
19    language: fortran
20    args: ./src/split_and_merge_modelC.f90
21    function: modelC_function
22    outputs: fortran_modelC:output
23
24  - name: fortran_modelD
25    language: fortran
26    args: ./src/split_and_merge_modelD.f90
27    function: modelD_function
28    outputs:
29      - name: fortran_modelD:output
30        vars:
31          - in_val1_copy
32          - in_val2_copy
33          - out_val
34
35connections:
36  - input: ./Input/input.txt
37    output: fortran_modelA:input
38    filetype: table
39  - input: fortran_modelA:output
40    outputs:
41      - fortran_modelB:input
42      - fortran_modelC:input
43    output_pattern: scatter
44  - inputs:
45      - fortran_modelB:output
46      - fortran_modelC:output
47    output: fortran_modelD:input
48    input_pattern: gather
49  - input: fortran_modelD:output
50    output: ./outputD.txt
51    filetype: table
52    field_units: g/s,g/s,g/s

Julia Version

Model Code:

1using Printf
2
3function modelA_function(in_val)
4  out_val1 = 2 * in_val
5  out_val2 = 3 * in_val
6  @printf("modelA_function(%s) = (%s, %s)\n", in_val, out_val1, out_val2)
7  return out_val1, out_val2
8end
1using Printf
2
3function modelB_function(in_val)
4  out_val = 3 * in_val
5  @printf("modelB_function(%s) = %s\n", in_val, out_val)
6  return out_val
7end
1using Printf
2
3function modelC_function(in_val)
4  out_val = 4 * in_val
5  @printf("modelC_function(%s) = %s\n", in_val, out_val)
6  return out_val
7end
1using Printf
2
3function modelD_function(in_val1, in_val2)
4  out_val = in_val1 + in_val2
5  @printf("modelD_function(%s, %s) = %s\n", in_val1, in_val2, out_val)
6  return in_val1, in_val2, out_val
7end

Model YAML:

 1models:
 2  - name: julia_modelA
 3    language: julia
 4    args: ./src/split_and_merge_modelA.jl
 5    function: modelA_function
 6
 7  - name: julia_modelB
 8    language: julia
 9    args: ./src/split_and_merge_modelB.jl
10    function: modelB_function
11
12  - name: julia_modelC
13    language: julia
14    args: ./src/split_and_merge_modelC.jl
15    function: modelC_function
16
17  - name: julia_modelD
18    language: julia
19    args: ./src/split_and_merge_modelD.jl
20    function: modelD_function
21
22connections:
23  - input: ./Input/input.txt
24    output: julia_modelA:input
25    filetype: table
26  - input: julia_modelA:output
27    outputs:
28      - julia_modelB:input
29      - julia_modelC:input
30    output_pattern: scatter
31  - inputs:
32      - julia_modelB:output
33      - julia_modelC:output
34    output: julia_modelD:input
35    input_pattern: gather
36  - input: julia_modelD:output
37    output: ./outputD.txt
38    filetype: table

Matlab Version

Model Code:

1function [out_val1, out_val2] = split_and_merge_modelA(in_val)
2  out_val1 = 2 * in_val;
3  out_val2 = 3 * in_val;
4  disp(sprintf('modelA_function(%f) = (%f, %f)', in_val, out_val1, out_val2));
5end
1function out_val = split_and_merge_modelB(in_val)
2  out_val = 3 * in_val;
3  disp(sprintf('modelB_function(%f) = %f', in_val, out_val));
4end
1function out_val = split_and_merge_modelC(in_val)
2  out_val = 4 * in_val;
3  disp(sprintf('modelC_function(%f) = %f', in_val, out_val));
4end
1function [in_val1, in_val2, out_val] = split_and_merge_modelD(in_val1, in_val2)
2  out_val = in_val1 + in_val2;
3  disp(sprintf('modelD_function(%f, %f) = %f', in_val1, in_val2, out_val));
4end

Model YAML:

 1models:
 2  - name: matlab_modelA
 3    language: matlab
 4    args: ./src/split_and_merge_modelA.m
 5    function: split_and_merge_modelA
 6
 7  - name: matlab_modelB
 8    language: matlab
 9    args: ./src/split_and_merge_modelB.m
10    function: split_and_merge_modelB
11
12  - name: matlab_modelC
13    language: matlab
14    args: ./src/split_and_merge_modelC.m
15    function: split_and_merge_modelC
16
17  - name: matlab_modelD
18    language: matlab
19    args: ./src/split_and_merge_modelD.m
20    function: split_and_merge_modelD
21
22connections:
23  - input: ./Input/input.txt
24    output: matlab_modelA:input
25    filetype: table
26  - input: matlab_modelA:output
27    outputs:
28      - matlab_modelB:input
29      - matlab_modelC:input
30    output_pattern: scatter
31  - inputs:
32      - matlab_modelB:output
33      - matlab_modelC:output
34    output: matlab_modelD:input
35    input_pattern: gather
36  - input: matlab_modelD:output
37    output: ./outputD.txt
38    filetype: table
39    field_units: g/s,g/s,g/s

Python Version

Model Code:

1def modelA_function(in_val):
2    out_val1 = 2 * in_val
3    out_val2 = 3 * in_val
4    print(f"modelA_function({in_val}) = ({out_val1}, {out_val2})")
5    return out_val1, out_val2
1def modelB_function(in_val):
2    out_val = 3 * in_val
3    print(f"modelB_function({in_val}) = {out_val}")
4    return out_val
1def modelC_function(in_val):
2    out_val = 4 * in_val
3    print(f"modelC_function({in_val}) = {out_val}")
4    return out_val
1def modelD_function(in_val1, in_val2):
2    out_val = in_val1 + in_val2
3    print(f"modelD_function({in_val1}, {in_val2}) = {out_val}")
4    return in_val1, in_val2, out_val

Model YAML:

 1models:
 2  - name: python_modelA
 3    language: python
 4    args: ./src/split_and_merge_modelA.py
 5    function: modelA_function
 6
 7  - name: python_modelB
 8    language: python
 9    args: ./src/split_and_merge_modelB.py
10    function: modelB_function
11
12  - name: python_modelC
13    language: python
14    args: ./src/split_and_merge_modelC.py
15    function: modelC_function
16
17  - name: python_modelD
18    language: python
19    args: ./src/split_and_merge_modelD.py
20    function: modelD_function
21
22connections:
23  - input: ./Input/input.txt
24    output: python_modelA:input
25    filetype: table
26  - input: python_modelA:output
27    outputs:
28      - python_modelB:input
29      - python_modelC:input
30    output_pattern: scatter
31  - inputs:
32      - python_modelB:output
33      - python_modelC:output
34    output: python_modelD:input
35    input_pattern: gather
36  - input: python_modelD:output
37    output: ./outputD.txt
38    filetype: table

R Version

Model Code:

1modelA_function <- function(in_val) {
2  out_val1 <- 2 * in_val
3  out_val2 <- 3 * in_val
4  print(sprintf("modelA_function(%f) = (%f, %f)", in_val, out_val1, out_val2))
5  return(list(out_val1,out_val2))
6}
1modelB_function <- function(in_val) {
2  out_val <- 3 * in_val
3  print(sprintf("modelB_function(%f) = %f", in_val, out_val))
4  return(out_val)
5}
1modelC_function <- function(in_val) {
2  out_val <- 4 * in_val
3  print(sprintf("modelC_function(%f) = %f", in_val, out_val))
4  return(out_val)
5}
1modelD_function <- function(in_val1, in_val2) {
2  out_val <- in_val1 + in_val2
3  print(sprintf("modelD_function(%f, %s) = %f", in_val1, in_val2, out_val))
4  return(list(in_val1, in_val2, out_val))
5}

Model YAML:

 1models:
 2  - name: R_modelA
 3    language: R
 4    args: ./src/split_and_merge_modelA.R
 5    function: modelA_function
 6
 7  - name: R_modelB
 8    language: R
 9    args: ./src/split_and_merge_modelB.R
10    function: modelB_function
11
12  - name: R_modelC
13    language: R
14    args: ./src/split_and_merge_modelC.R
15    function: modelC_function
16
17  - name: R_modelD
18    language: R
19    args: ./src/split_and_merge_modelD.R
20    function: modelD_function
21
22connections:
23  - input: ./Input/input.txt
24    output: R_modelA:input
25    filetype: table
26  - input: R_modelA:output
27    outputs:
28      - R_modelB:input
29      - R_modelC:input
30    output_pattern: scatter
31  - inputs:
32      - R_modelB:output
33      - R_modelC:output
34    output: R_modelD:input
35    input_pattern: gather
36  - input: R_modelD:output
37    output: ./outputD.txt
38    filetype: table