SaM¶
One model that receives input from two files and sends output to one file in the temporary directory. The YAML uses the deprecated driver-based method to represent connections.
Mixed Version¶
Model Code:
1#include <stdio.h>
2#include <stdlib.h>
3#include "YggInterface.h"
4
5#define BSIZE 1000
6
7
8int main() {
9 int ret;
10 char adata[BSIZE];
11 char bdata[BSIZE];
12 char outbuf[BSIZE];
13
14 // Get input and output channels matching yaml
15 yggInput_t in1 = yggInput("input1_c");
16 yggInput_t in2 = yggInput("static_c");
17 yggOutput_t out1 = yggOutput("output_c");
18 printf("SaM(C): Set up I/O channels\n");
19
20 // Get input from input1 channel
21 ret = ygg_recv(in1, adata, BSIZE);
22 if (ret < 0) {
23 printf("SaM(C): ERROR RECV from input1\n");
24 return -1;
25 }
26 int a = atoi(adata);
27 printf("SaM(C): Received %d from input1\n", a);
28
29 // Get input from static channel
30 ret = ygg_recv(in2, bdata, BSIZE);
31 if (ret < 0) {
32 printf("SaM(C): ERROR RECV from static\n");
33 return -1;
34 }
35 int b = atoi(bdata);
36 printf("SaM(C): Received %d from static\n", b);
37
38 // Compute sum and send message to output channel
39 int sum = a + b;
40 sprintf(outbuf, "%d", sum);
41 ret = ygg_send(out1, outbuf, strlen(outbuf));
42 if (ret != 0) {
43 printf("SaM(C): ERROR SEND to output\n");
44 return -1;
45 }
46 printf("SaM(C): Sent to output\n");
47
48 return 0;
49}
1#include <stdio.h>
2#include <stdlib.h>
3#include "YggInterface.hpp"
4
5#define BSIZE 1000
6
7
8int main() {
9 int ret;
10 char adata[BSIZE];
11 char bdata[BSIZE];
12 char outbuf[BSIZE];
13
14 // Get input and output channels matching yaml
15 YggInput in1("input1_cpp");
16 YggInput in2("static_cpp");
17 YggOutput out1("output_cpp");
18 printf("SaM(CPP): Set up I/O channels\n");
19
20 // Get input from input1 channel
21 ret = in1.recv(adata, BSIZE);
22 if (ret < 0) {
23 printf("SaM(CPP): ERROR RECV from input1\n");
24 return -1;
25 }
26 int a = atoi(adata);
27 printf("SaM(CPP): Received %d from input1\n", a);
28
29 // Get input from static channel
30 ret = in2.recv(bdata, BSIZE);
31 if (ret < 0) {
32 printf("SaM(CPP): ERROR RECV from static\n");
33 return -1;
34 }
35 int b = atoi(bdata);
36 printf("SaM(CPP): Received %d from static\n", b);
37
38 // Compute sum and send message to output channel
39 int sum = a + b;
40 sprintf(outbuf, "%d", sum);
41 ret = out1.send(outbuf, strlen(outbuf));
42 if (ret != 0) {
43 printf("SaM(CPP): ERROR SEND to output\n");
44 return -1;
45 }
46 printf("SaM(CPP): Sent to output\n");
47
48 return 0;
49}
1PROGRAM SaM
2 USE fygg
3
4 integer, parameter :: BSIZE = 1000
5 integer :: bufsiz, a, b, sum
6 character(len = 1000) :: adata, bdata, outbuf
7 TYPE(yggcomm) :: in1, in2, out1
8 logical :: ret = .true.
9
10 ! Get input and output channels matching yaml
11 in1 = ygg_input("input1_fortran")
12 in2 = ygg_input("static_fortran")
13 out1 = ygg_output("output_fortran")
14
15 ! Get input from input1 channel
16 bufsiz = BSIZE
17 ret = ygg_recv(in1, adata, bufsiz)
18 IF (.not.ret) THEN
19 PRINT *, "SaM(Fortran): ERROR RECV from input1"
20 STOP 1
21 END IF
22 READ(adata, '(I4)') a
23 PRINT *, "SaM(Fortran): Received ", a, " from input1"
24
25 ! Get input from static channel
26 bufsiz = BSIZE
27 ret = ygg_recv(in2, bdata, bufsiz)
28 IF (.not.ret) THEN
29 PRINT *, "SaM(Fortran): ERROR RECV from static"
30 STOP 1
31 END IF
32 READ(bdata, '(I4)') b
33 PRINT *, "SaM(Fortran): Received ", b, " from static"
34
35 ! Compute sum and send message to output channel
36 sum = a + b
37 WRITE(outbuf, '(I4)') sum
38 outbuf = ADJUSTL(outbuf)
39 ret = ygg_send(out1, outbuf, LEN_TRIM(outbuf))
40 IF (.not.ret) THEN
41 PRINT *, "SaM(Fortran): ERROR SEND to output"
42 STOP 1
43 END IF
44 PRINT *, "SaM(Fortran): Sent to output"
45
46END PROGRAM SaM
1using Yggdrasil
2using Printf
3
4# Get input and output channels matching yaml
5in1 = Yggdrasil.YggInterface("YggInput", "input1_julia")
6in2 = Yggdrasil.YggInterface("YggInput", "static_julia")
7out1 = Yggdrasil.YggInterface("YggOutput", "output_julia")
8
9# Get input from input1 channel
10ret, adata = in1.recv()
11if (!ret)
12 error("SaM(julia): ERROR RECV from input1")
13end
14a = parse(Int32, adata)
15@printf("SaM(julia): Received %d from input1\n", a)
16
17# Get input from static channel
18ret, bdata = in2.recv()
19if (!ret)
20 error("SaM(julia): ERROR RECV from static")
21end
22b = parse(Int32, bdata)
23@printf("SaM(julia): Received %d from static\n", b)
24
25# Compute sum and send message to output channel
26sum = a + b
27outdata = @sprintf("%d", sum)
28ret = out1.send(outdata)
29if (!ret)
30 error("SaM(julia): ERROR SEND to output")
31end
32println("SaM(julia): Sent to output")
1% Get input and output channels matching yaml
2in1 = YggInterface('YggInput', 'input1_matlab');
3in2 = YggInterface('YggInput', 'static_matlab');
4out1 = YggInterface('YggOutput', 'output_matlab');
5disp('SaM(M): Set up I/O channels');
6
7% Get input from input1 channel
8[flag, var] = in1.recv();
9if (~flag);
10 error('SaM(M): ERROR RECV from input1');
11end
12a = str2num(var);
13fprintf('SaM(M): Received %d from input1\n', a);
14
15% Get input from static channel
16[flag, var] = in2.recv();
17if (~flag);
18 error('SaM(M): ERROR RECV from static');
19end
20b = str2num(var);
21fprintf('SaM(M): Received %d from static\n', b);
22
23% Compute sum and send message to output channel
24sum = a + b;
25ret = out1.send(int2str(sum));
26if (~ret);
27 error('SaM(M): ERROR SEND to output');
28end
29disp('SaM(M): Sent to output');
1#!/usr/bin/python
2from yggdrasil.interface.YggInterface import YggInput, YggOutput
3
4
5if __name__ == '__main__':
6
7 # Get input and output channels matching yaml
8 in1 = YggInput('input1_python')
9 in2 = YggInput('static_python')
10 out1 = YggOutput('output_python')
11 print('SaM(P): Set up I/O channels')
12
13 # Get input from input1 channel
14 ret, adata = in1.recv()
15 if not ret:
16 raise RuntimeError('SaM(P): ERROR RECV from input1')
17 a = int(adata)
18 print('SaM(P): Received %d from input1' % a)
19
20 # Get input from static channel
21 ret, bdata = in2.recv()
22 if not ret:
23 raise RuntimeError('SaM(P): ERROR RECV from static')
24 b = int(bdata)
25 print('SaM(P): Received %d from static' % b)
26
27 # Compute sum and send message to output channel
28 sum = a + b
29 outdata = '%d' % sum
30 ret = out1.send(outdata)
31 if not ret:
32 raise RuntimeError('SaM(P): ERROR SEND to output')
33 print('SaM(P): Sent to output')
1library(yggdrasil)
2
3
4# Get input and output channels matching yaml
5in1 <- YggInterface('YggInput', 'input1_R')
6in2 <- YggInterface('YggInput', 'static_R')
7out1 <- YggInterface('YggOutput', 'output_R')
8print('SaM(R): Set up I/O channels')
9
10# Get input from input1 channel
11c(ret, adata) %<-% in1$recv()
12if (!ret) {
13 stop('SaM(R): ERROR RECV from input1')
14}
15a <- strtoi(adata)
16fprintf('SaM(R): Received %d from input1', a)
17
18# Get input from static channel
19c(ret, bdata) %<-% in2$recv()
20if (!ret) {
21 stop('SaM(R): ERROR RECV from static')
22}
23b <- strtoi(bdata)
24fprintf('SaM(R): Received %d from static', b)
25
26# Compute sum and send message to output channel
27sum <- a + b
28outdata = sprintf('%d', sum)
29ret <- out1$send(outdata)
30if (!ret) {
31 stop('SaM(R): ERROR SEND to output')
32}
33print('SaM(R): Sent to output')
Model YAML:
1---
2
3models:
4 - name: SaM_c
5 driver: GCCModelDriver
6 args: src/SaM.c
7
8 inputs:
9 - name: input1_c
10 driver: FileInputDriver
11 args: ./Input/SaM_input.txt
12 - name: static_c
13 driver: FileInputDriver
14 args: ./Input/SaM_static.txt
15
16 outputs:
17 - name: output_c
18 driver: OutputDriver
19 args: output_c
20
21 - name: SaM_python
22 driver: PythonModelDriver
23 args: src/SaM.py
24
25 inputs:
26 - name: input1_python
27 driver: InputDriver
28 args: output_c
29 - name: static_python
30 driver: FileInputDriver
31 args: ./Input/SaM_static.txt
32
33 outputs:
34 - name: output_python
35 driver: OutputDriver
36 args: output_python
37
38 - name: SaM_cpp
39 driver: GCCModelDriver
40 args: src/SaM.cpp
41
42 inputs:
43 - name: input1_cpp
44 driver: InputDriver
45 args: output_python
46 - name: static_cpp
47 driver: FileInputDriver
48 args: ./Input/SaM_static.txt
49
50 outputs:
51 - name: output_cpp
52 driver: OutputDriver
53 args: output_cpp
54
55 - name: SaM_fortran
56 driver: FortranModelDriver
57 args: src/SaM.f90
58
59 inputs:
60 - name: input1_fortran
61 driver: InputDriver
62 args: output_cpp
63 - name: static_fortran
64 driver: FileInputDriver
65 args: ./Input/SaM_static.txt
66
67 outputs:
68 - name: output_fortran
69 driver: OutputDriver
70 args: output_fortran
71
72 - name: SaM_matlab
73 driver: MatlabModelDriver
74 args: src/SaM.m
75
76 inputs:
77 - name: input1_matlab
78 driver: InputDriver
79 args: output_fortran
80 - name: static_matlab
81 driver: FileInputDriver
82 args: ./Input/SaM_static.txt
83
84 outputs:
85 - name: output_matlab
86 driver: FileOutputDriver
87 args: SaM_output.txt
88 in_temp: True
Mixed w/o Matlab Version¶
Model Code:
1#include <stdio.h>
2#include <stdlib.h>
3#include "YggInterface.h"
4
5#define BSIZE 1000
6
7
8int main() {
9 int ret;
10 char adata[BSIZE];
11 char bdata[BSIZE];
12 char outbuf[BSIZE];
13
14 // Get input and output channels matching yaml
15 yggInput_t in1 = yggInput("input1_c");
16 yggInput_t in2 = yggInput("static_c");
17 yggOutput_t out1 = yggOutput("output_c");
18 printf("SaM(C): Set up I/O channels\n");
19
20 // Get input from input1 channel
21 ret = ygg_recv(in1, adata, BSIZE);
22 if (ret < 0) {
23 printf("SaM(C): ERROR RECV from input1\n");
24 return -1;
25 }
26 int a = atoi(adata);
27 printf("SaM(C): Received %d from input1\n", a);
28
29 // Get input from static channel
30 ret = ygg_recv(in2, bdata, BSIZE);
31 if (ret < 0) {
32 printf("SaM(C): ERROR RECV from static\n");
33 return -1;
34 }
35 int b = atoi(bdata);
36 printf("SaM(C): Received %d from static\n", b);
37
38 // Compute sum and send message to output channel
39 int sum = a + b;
40 sprintf(outbuf, "%d", sum);
41 ret = ygg_send(out1, outbuf, strlen(outbuf));
42 if (ret != 0) {
43 printf("SaM(C): ERROR SEND to output\n");
44 return -1;
45 }
46 printf("SaM(C): Sent to output\n");
47
48 return 0;
49}
1#include <stdio.h>
2#include <stdlib.h>
3#include "YggInterface.hpp"
4
5#define BSIZE 1000
6
7
8int main() {
9 int ret;
10 char adata[BSIZE];
11 char bdata[BSIZE];
12 char outbuf[BSIZE];
13
14 // Get input and output channels matching yaml
15 YggInput in1("input1_cpp");
16 YggInput in2("static_cpp");
17 YggOutput out1("output_cpp");
18 printf("SaM(CPP): Set up I/O channels\n");
19
20 // Get input from input1 channel
21 ret = in1.recv(adata, BSIZE);
22 if (ret < 0) {
23 printf("SaM(CPP): ERROR RECV from input1\n");
24 return -1;
25 }
26 int a = atoi(adata);
27 printf("SaM(CPP): Received %d from input1\n", a);
28
29 // Get input from static channel
30 ret = in2.recv(bdata, BSIZE);
31 if (ret < 0) {
32 printf("SaM(CPP): ERROR RECV from static\n");
33 return -1;
34 }
35 int b = atoi(bdata);
36 printf("SaM(CPP): Received %d from static\n", b);
37
38 // Compute sum and send message to output channel
39 int sum = a + b;
40 sprintf(outbuf, "%d", sum);
41 ret = out1.send(outbuf, strlen(outbuf));
42 if (ret != 0) {
43 printf("SaM(CPP): ERROR SEND to output\n");
44 return -1;
45 }
46 printf("SaM(CPP): Sent to output\n");
47
48 return 0;
49}
1PROGRAM SaM
2 USE fygg
3
4 integer, parameter :: BSIZE = 1000
5 integer :: bufsiz, a, b, sum
6 character(len = 1000) :: adata, bdata, outbuf
7 TYPE(yggcomm) :: in1, in2, out1
8 logical :: ret = .true.
9
10 ! Get input and output channels matching yaml
11 in1 = ygg_input("input1_fortran")
12 in2 = ygg_input("static_fortran")
13 out1 = ygg_output("output_fortran")
14
15 ! Get input from input1 channel
16 bufsiz = BSIZE
17 ret = ygg_recv(in1, adata, bufsiz)
18 IF (.not.ret) THEN
19 PRINT *, "SaM(Fortran): ERROR RECV from input1"
20 STOP 1
21 END IF
22 READ(adata, '(I4)') a
23 PRINT *, "SaM(Fortran): Received ", a, " from input1"
24
25 ! Get input from static channel
26 bufsiz = BSIZE
27 ret = ygg_recv(in2, bdata, bufsiz)
28 IF (.not.ret) THEN
29 PRINT *, "SaM(Fortran): ERROR RECV from static"
30 STOP 1
31 END IF
32 READ(bdata, '(I4)') b
33 PRINT *, "SaM(Fortran): Received ", b, " from static"
34
35 ! Compute sum and send message to output channel
36 sum = a + b
37 WRITE(outbuf, '(I4)') sum
38 outbuf = ADJUSTL(outbuf)
39 ret = ygg_send(out1, outbuf, LEN_TRIM(outbuf))
40 IF (.not.ret) THEN
41 PRINT *, "SaM(Fortran): ERROR SEND to output"
42 STOP 1
43 END IF
44 PRINT *, "SaM(Fortran): Sent to output"
45
46END PROGRAM SaM
1using Yggdrasil
2using Printf
3
4# Get input and output channels matching yaml
5in1 = Yggdrasil.YggInterface("YggInput", "input1_julia")
6in2 = Yggdrasil.YggInterface("YggInput", "static_julia")
7out1 = Yggdrasil.YggInterface("YggOutput", "output_julia")
8
9# Get input from input1 channel
10ret, adata = in1.recv()
11if (!ret)
12 error("SaM(julia): ERROR RECV from input1")
13end
14a = parse(Int32, adata)
15@printf("SaM(julia): Received %d from input1\n", a)
16
17# Get input from static channel
18ret, bdata = in2.recv()
19if (!ret)
20 error("SaM(julia): ERROR RECV from static")
21end
22b = parse(Int32, bdata)
23@printf("SaM(julia): Received %d from static\n", b)
24
25# Compute sum and send message to output channel
26sum = a + b
27outdata = @sprintf("%d", sum)
28ret = out1.send(outdata)
29if (!ret)
30 error("SaM(julia): ERROR SEND to output")
31end
32println("SaM(julia): Sent to output")
1#!/usr/bin/python
2from yggdrasil.interface.YggInterface import YggInput, YggOutput
3
4
5if __name__ == '__main__':
6
7 # Get input and output channels matching yaml
8 in1 = YggInput('input1_python')
9 in2 = YggInput('static_python')
10 out1 = YggOutput('output_python')
11 print('SaM(P): Set up I/O channels')
12
13 # Get input from input1 channel
14 ret, adata = in1.recv()
15 if not ret:
16 raise RuntimeError('SaM(P): ERROR RECV from input1')
17 a = int(adata)
18 print('SaM(P): Received %d from input1' % a)
19
20 # Get input from static channel
21 ret, bdata = in2.recv()
22 if not ret:
23 raise RuntimeError('SaM(P): ERROR RECV from static')
24 b = int(bdata)
25 print('SaM(P): Received %d from static' % b)
26
27 # Compute sum and send message to output channel
28 sum = a + b
29 outdata = '%d' % sum
30 ret = out1.send(outdata)
31 if not ret:
32 raise RuntimeError('SaM(P): ERROR SEND to output')
33 print('SaM(P): Sent to output')
1library(yggdrasil)
2
3
4# Get input and output channels matching yaml
5in1 <- YggInterface('YggInput', 'input1_R')
6in2 <- YggInterface('YggInput', 'static_R')
7out1 <- YggInterface('YggOutput', 'output_R')
8print('SaM(R): Set up I/O channels')
9
10# Get input from input1 channel
11c(ret, adata) %<-% in1$recv()
12if (!ret) {
13 stop('SaM(R): ERROR RECV from input1')
14}
15a <- strtoi(adata)
16fprintf('SaM(R): Received %d from input1', a)
17
18# Get input from static channel
19c(ret, bdata) %<-% in2$recv()
20if (!ret) {
21 stop('SaM(R): ERROR RECV from static')
22}
23b <- strtoi(bdata)
24fprintf('SaM(R): Received %d from static', b)
25
26# Compute sum and send message to output channel
27sum <- a + b
28outdata = sprintf('%d', sum)
29ret <- out1$send(outdata)
30if (!ret) {
31 stop('SaM(R): ERROR SEND to output')
32}
33print('SaM(R): Sent to output')
Model YAML:
1---
2
3models:
4 - name: SaM_c
5 driver: GCCModelDriver
6 args: src/SaM.c
7
8 inputs:
9 - name: input1_c
10 driver: FileInputDriver
11 args: ./Input/SaM_input.txt
12 - name: static_c
13 driver: FileInputDriver
14 args: ./Input/SaM_static.txt
15
16 outputs:
17 - name: output_c
18 driver: OutputDriver
19 args: output_c
20
21 - name: SaM_python
22 driver: PythonModelDriver
23 args: src/SaM.py
24
25 inputs:
26 - name: input1_python
27 driver: InputDriver
28 args: output_c
29 - name: static_python
30 driver: FileInputDriver
31 args: ./Input/SaM_static.txt
32
33 outputs:
34 - name: output_python
35 driver: OutputDriver
36 args: output_python
37
38 - name: SaM_cpp
39 driver: GCCModelDriver
40 args: src/SaM.cpp
41
42 inputs:
43 - name: input1_cpp
44 driver: InputDriver
45 args: output_python
46 - name: static_cpp
47 driver: FileInputDriver
48 args: ./Input/SaM_static.txt
49
50 outputs:
51 - name: output_cpp
52 driver: OutputDriver
53 args: output_cpp
54
55 - name: SaM_fortran
56 driver: FortranModelDriver
57 args: src/SaM.f90
58
59 inputs:
60 - name: input1_fortran
61 driver: InputDriver
62 args: output_cpp
63 - name: static_fortran
64 driver: FileInputDriver
65 args: ./Input/SaM_static.txt
66
67 outputs:
68 - name: output_fortran
69 driver: FileOutputDriver
70 args: SaM_output.txt
71 in_temp: True
C Version¶
Model Code:
1#include <stdio.h>
2#include <stdlib.h>
3#include "YggInterface.h"
4
5#define BSIZE 1000
6
7
8int main() {
9 int ret;
10 char adata[BSIZE];
11 char bdata[BSIZE];
12 char outbuf[BSIZE];
13
14 // Get input and output channels matching yaml
15 yggInput_t in1 = yggInput("input1_c");
16 yggInput_t in2 = yggInput("static_c");
17 yggOutput_t out1 = yggOutput("output_c");
18 printf("SaM(C): Set up I/O channels\n");
19
20 // Get input from input1 channel
21 ret = ygg_recv(in1, adata, BSIZE);
22 if (ret < 0) {
23 printf("SaM(C): ERROR RECV from input1\n");
24 return -1;
25 }
26 int a = atoi(adata);
27 printf("SaM(C): Received %d from input1\n", a);
28
29 // Get input from static channel
30 ret = ygg_recv(in2, bdata, BSIZE);
31 if (ret < 0) {
32 printf("SaM(C): ERROR RECV from static\n");
33 return -1;
34 }
35 int b = atoi(bdata);
36 printf("SaM(C): Received %d from static\n", b);
37
38 // Compute sum and send message to output channel
39 int sum = a + b;
40 sprintf(outbuf, "%d", sum);
41 ret = ygg_send(out1, outbuf, strlen(outbuf));
42 if (ret != 0) {
43 printf("SaM(C): ERROR SEND to output\n");
44 return -1;
45 }
46 printf("SaM(C): Sent to output\n");
47
48 return 0;
49}
Model YAML:
1---
2
3model:
4 name: SaMC
5 driver: GCCModelDriver
6 args: ./src/SaM.c
7
8 inputs:
9 - name: input1_c
10 driver: FileInputDriver
11 args: ./Input/SaM_input.txt
12 - name: static_c
13 driver: FileInputDriver
14 args: ./Input/SaM_static.txt
15
16 outputs:
17 - name: output_c
18 driver: FileOutputDriver
19 args: SaM_output.txt
20 in_temp: True
C++ Version¶
Model Code:
1#include <stdio.h>
2#include <stdlib.h>
3#include "YggInterface.hpp"
4
5#define BSIZE 1000
6
7
8int main() {
9 int ret;
10 char adata[BSIZE];
11 char bdata[BSIZE];
12 char outbuf[BSIZE];
13
14 // Get input and output channels matching yaml
15 YggInput in1("input1_cpp");
16 YggInput in2("static_cpp");
17 YggOutput out1("output_cpp");
18 printf("SaM(CPP): Set up I/O channels\n");
19
20 // Get input from input1 channel
21 ret = in1.recv(adata, BSIZE);
22 if (ret < 0) {
23 printf("SaM(CPP): ERROR RECV from input1\n");
24 return -1;
25 }
26 int a = atoi(adata);
27 printf("SaM(CPP): Received %d from input1\n", a);
28
29 // Get input from static channel
30 ret = in2.recv(bdata, BSIZE);
31 if (ret < 0) {
32 printf("SaM(CPP): ERROR RECV from static\n");
33 return -1;
34 }
35 int b = atoi(bdata);
36 printf("SaM(CPP): Received %d from static\n", b);
37
38 // Compute sum and send message to output channel
39 int sum = a + b;
40 sprintf(outbuf, "%d", sum);
41 ret = out1.send(outbuf, strlen(outbuf));
42 if (ret != 0) {
43 printf("SaM(CPP): ERROR SEND to output\n");
44 return -1;
45 }
46 printf("SaM(CPP): Sent to output\n");
47
48 return 0;
49}
Model YAML:
1---
2
3model:
4 name: SaM_cpp
5 driver: GCCModelDriver
6 args: ./src/SaM.cpp
7
8 inputs:
9 - name: input1_cpp
10 driver: FileInputDriver
11 args: ./Input/SaM_input.txt
12 - name: static_cpp
13 driver: FileInputDriver
14 args: ./Input/SaM_static.txt
15
16 outputs:
17 - name: output_cpp
18 driver: FileOutputDriver
19 args: SaM_output.txt
20 in_temp: True
Fortran Version¶
Model Code:
1PROGRAM SaM
2 USE fygg
3
4 integer, parameter :: BSIZE = 1000
5 integer :: bufsiz, a, b, sum
6 character(len = 1000) :: adata, bdata, outbuf
7 TYPE(yggcomm) :: in1, in2, out1
8 logical :: ret = .true.
9
10 ! Get input and output channels matching yaml
11 in1 = ygg_input("input1_fortran")
12 in2 = ygg_input("static_fortran")
13 out1 = ygg_output("output_fortran")
14
15 ! Get input from input1 channel
16 bufsiz = BSIZE
17 ret = ygg_recv(in1, adata, bufsiz)
18 IF (.not.ret) THEN
19 PRINT *, "SaM(Fortran): ERROR RECV from input1"
20 STOP 1
21 END IF
22 READ(adata, '(I4)') a
23 PRINT *, "SaM(Fortran): Received ", a, " from input1"
24
25 ! Get input from static channel
26 bufsiz = BSIZE
27 ret = ygg_recv(in2, bdata, bufsiz)
28 IF (.not.ret) THEN
29 PRINT *, "SaM(Fortran): ERROR RECV from static"
30 STOP 1
31 END IF
32 READ(bdata, '(I4)') b
33 PRINT *, "SaM(Fortran): Received ", b, " from static"
34
35 ! Compute sum and send message to output channel
36 sum = a + b
37 WRITE(outbuf, '(I4)') sum
38 outbuf = ADJUSTL(outbuf)
39 ret = ygg_send(out1, outbuf, LEN_TRIM(outbuf))
40 IF (.not.ret) THEN
41 PRINT *, "SaM(Fortran): ERROR SEND to output"
42 STOP 1
43 END IF
44 PRINT *, "SaM(Fortran): Sent to output"
45
46END PROGRAM SaM
Model YAML:
1---
2
3model:
4 name: SaMFortran
5 driver: FortranModelDriver
6 args: src/SaM.f90
7
8 inputs:
9 - name: input1_fortran
10 driver: FileInputDriver
11 args: ./Input/SaM_input.txt
12 - name: static_fortran
13 driver: FileInputDriver
14 args: ./Input/SaM_static.txt
15
16 outputs:
17 - name: output_fortran
18 driver: FileOutputDriver
19 args: SaM_output.txt
20 in_temp: True
Julia Version¶
Model Code:
1using Yggdrasil
2using Printf
3
4# Get input and output channels matching yaml
5in1 = Yggdrasil.YggInterface("YggInput", "input1_julia")
6in2 = Yggdrasil.YggInterface("YggInput", "static_julia")
7out1 = Yggdrasil.YggInterface("YggOutput", "output_julia")
8
9# Get input from input1 channel
10ret, adata = in1.recv()
11if (!ret)
12 error("SaM(julia): ERROR RECV from input1")
13end
14a = parse(Int32, adata)
15@printf("SaM(julia): Received %d from input1\n", a)
16
17# Get input from static channel
18ret, bdata = in2.recv()
19if (!ret)
20 error("SaM(julia): ERROR RECV from static")
21end
22b = parse(Int32, bdata)
23@printf("SaM(julia): Received %d from static\n", b)
24
25# Compute sum and send message to output channel
26sum = a + b
27outdata = @sprintf("%d", sum)
28ret = out1.send(outdata)
29if (!ret)
30 error("SaM(julia): ERROR SEND to output")
31end
32println("SaM(julia): Sent to output")
Model YAML:
1---
2
3model:
4 name: SaMJulia
5 driver: JuliaModelDriver
6 args: src/SaM.jl
7
8 inputs:
9 - name: input1_julia
10 driver: FileInputDriver
11 args: ./Input/SaM_input.txt
12 - name: static_julia
13 driver: FileInputDriver
14 args: ./Input/SaM_static.txt
15
16 outputs:
17 - name: output_julia
18 driver: FileOutputDriver
19 args: SaM_output.txt
20 in_temp: True
Matlab Version¶
Model Code:
1% Get input and output channels matching yaml
2in1 = YggInterface('YggInput', 'input1_matlab');
3in2 = YggInterface('YggInput', 'static_matlab');
4out1 = YggInterface('YggOutput', 'output_matlab');
5disp('SaM(M): Set up I/O channels');
6
7% Get input from input1 channel
8[flag, var] = in1.recv();
9if (~flag);
10 error('SaM(M): ERROR RECV from input1');
11end
12a = str2num(var);
13fprintf('SaM(M): Received %d from input1\n', a);
14
15% Get input from static channel
16[flag, var] = in2.recv();
17if (~flag);
18 error('SaM(M): ERROR RECV from static');
19end
20b = str2num(var);
21fprintf('SaM(M): Received %d from static\n', b);
22
23% Compute sum and send message to output channel
24sum = a + b;
25ret = out1.send(int2str(sum));
26if (~ret);
27 error('SaM(M): ERROR SEND to output');
28end
29disp('SaM(M): Sent to output');
Model YAML:
1---
2
3model:
4 name: MatlabSaM
5 driver: MatlabModelDriver
6 args: src/SaM.m
7
8 inputs:
9 - name: input1_matlab
10 driver: FileInputDriver
11 args: ./Input/SaM_input.txt
12 - name: static_matlab
13 driver: FileInputDriver
14 args: ./Input/SaM_static.txt
15
16 outputs:
17 - name: output_matlab
18 driver: FileOutputDriver
19 args: SaM_output.txt
20 in_temp: True
Python Version¶
Model Code:
1#!/usr/bin/python
2from yggdrasil.interface.YggInterface import YggInput, YggOutput
3
4
5if __name__ == '__main__':
6
7 # Get input and output channels matching yaml
8 in1 = YggInput('input1_python')
9 in2 = YggInput('static_python')
10 out1 = YggOutput('output_python')
11 print('SaM(P): Set up I/O channels')
12
13 # Get input from input1 channel
14 ret, adata = in1.recv()
15 if not ret:
16 raise RuntimeError('SaM(P): ERROR RECV from input1')
17 a = int(adata)
18 print('SaM(P): Received %d from input1' % a)
19
20 # Get input from static channel
21 ret, bdata = in2.recv()
22 if not ret:
23 raise RuntimeError('SaM(P): ERROR RECV from static')
24 b = int(bdata)
25 print('SaM(P): Received %d from static' % b)
26
27 # Compute sum and send message to output channel
28 sum = a + b
29 outdata = '%d' % sum
30 ret = out1.send(outdata)
31 if not ret:
32 raise RuntimeError('SaM(P): ERROR SEND to output')
33 print('SaM(P): Sent to output')
Model YAML:
1---
2
3model:
4 name: SaMPython
5 driver: PythonModelDriver
6 args: src/SaM.py
7
8 inputs:
9 - name: input1_python
10 driver: FileInputDriver
11 args: ./Input/SaM_input.txt
12 - name: static_python
13 driver: FileInputDriver
14 args: ./Input/SaM_static.txt
15
16 outputs:
17 - name: output_python
18 driver: FileOutputDriver
19 args: SaM_output.txt
20 in_temp: True
R Version¶
Model Code:
1library(yggdrasil)
2
3
4# Get input and output channels matching yaml
5in1 <- YggInterface('YggInput', 'input1_R')
6in2 <- YggInterface('YggInput', 'static_R')
7out1 <- YggInterface('YggOutput', 'output_R')
8print('SaM(R): Set up I/O channels')
9
10# Get input from input1 channel
11c(ret, adata) %<-% in1$recv()
12if (!ret) {
13 stop('SaM(R): ERROR RECV from input1')
14}
15a <- strtoi(adata)
16fprintf('SaM(R): Received %d from input1', a)
17
18# Get input from static channel
19c(ret, bdata) %<-% in2$recv()
20if (!ret) {
21 stop('SaM(R): ERROR RECV from static')
22}
23b <- strtoi(bdata)
24fprintf('SaM(R): Received %d from static', b)
25
26# Compute sum and send message to output channel
27sum <- a + b
28outdata = sprintf('%d', sum)
29ret <- out1$send(outdata)
30if (!ret) {
31 stop('SaM(R): ERROR SEND to output')
32}
33print('SaM(R): Sent to output')
Model YAML:
1---
2
3model:
4 name: SaMR
5 driver: RModelDriver
6 args: src/SaM.R
7
8 inputs:
9 - name: input1_R
10 driver: FileInputDriver
11 args: ./Input/SaM_input.txt
12 - name: static_R
13 driver: FileInputDriver
14 args: ./Input/SaM_static.txt
15
16 outputs:
17 - name: output_R
18 driver: FileOutputDriver
19 args: SaM_output.txt
20 in_temp: True