=====Examples of ASSIST code=====
I gathered here a few simple ASSIST programs (chosen among the ASSIST framework regression tests) as concrete examples of the ASSIST programming syntax.
====Simple process graphs, "none" topology parmod====
===grafo.ast===
// -*- C++ -*-
#define N 10
generic main()
{
stream long A1;
stream long A2;
stream long[N] B1;
stream long[N] B2;
stream long C1;
stream long C2;
stream bool D1;
stream bool D2;
genera1 ( output_stream A1);
genera2 ( output_stream A2);
p1 (input_stream A1 output_stream B1);
p2 (input_stream A2 output_stream B2);
cross (input_stream B1,B2 output_stream C1,C2);
p3 (input_stream C1 output_stream D1);
p4 (input_stream C2 output_stream D2);
fine (input_stream D1,D2);
}
genera1(output_stream long A1) {
fgen1(output_stream A1);
}
proc fgen1(output_stream long A1)
inc<"iostream">
$c++{
long a;
// start message for regression test
std::cerr << "STARTING genera1" << std::endl;
for (int i=0;i
$c++{
long a;
// start message for regression test
std::cerr << "STARTING genera2" << std::endl;
for (int i=0;i
$c++{
long c1 = 0;
long c2 = 0;
for (int i=0;i
$c++{
static int count;
static int ok = 0;
if ((D1 != true) || (D2 !=false)) ok = -1;
count++;
if (count >= N) {
// termination message for regression test
if (ok==0)
std::cerr << "ENDING with SUCCESS grafo.ast" << std::endl;
else
std::cerr << "ENDING with FAILURE grafo.ast" << std::endl;
}
}c++$
proc f_p1(in long A1 output_stream long B1[N])
inc<"iostream">
$c++{
long b[N];
b[0] = A1;
for (int i=1;i
$c++{
long b[N];
b[0] = A2;
for (int i=1;i
$c++{
bool d1 = true;
assist_out(D1,d1);
}c++$
proc f_p4(in long C2 output_stream bool D2)
inc<"iostream">
$c++{
bool d2 = false;
assist_out(D2,d2);
}c++$
===pipeline.ast===
// -*- C++ -*-
#define N 10
#define MAX_ITER 10
#define FILE_OUT "/tmp/risultato.txt"
/* ------------------------------------------------------------ */
/* Test of a simple pipeline with a parmod none as middle stage */
/* here the proc elements have been written in C++ */
/* ------------------------------------------------------------ */
typedef struct {
long x;
long y;
} T_cart;
generic main()
{
stream T_cart[N] A;
stream T_cart[N] B;
genera (output_stream A);
elabora (input_stream A output_stream B);
stampa (input_stream B);
}
genera (output_stream T_cart A[N]) {
Fgenera (output_stream A);
}
proc Fgenera (output_stream T_cart A[N])
inc<"iostream">
$c++{
T_cart tmp_A[N];
// start message for regression test
std::cerr << "STARTING gen" << std::endl;
for (int k=0; k
$c++{
std::ofstream f;
static int file_aperto = -1;
static int count = 0;
static int ok = 0;
if (file_aperto == -1) {
f.open (FILE_OUT);
file_aperto = 0;
}
for(int i=0; i= MAX_ITER) {
f.close();
// termination message for regression test
if (ok==0)
std::cerr << "ENDING with SUCCESS pipeline.ast --> stampa su file " << FILE_OUT << std::endl;
else
std::cerr << "ENDING with FAILURE pipeline.ast --> stampa su file " << FILE_OUT << std::endl;
}
}c++$
proc Felab (in T_cart A[N] out T_cart B[N])
inc<"iostream">
$c++{
static int count= 0;
//std::cerr << " Felab " << count++ << std::endl;
for (int i=0; i
===pipeline_C.ast===
// -*- C++ -*-
#define N 10
#define MAX_ITER 10
/* ------------------------------------------------------------ */
/* Test of a simple pipeline with a parmod none as middle stage */
/* here the proc elements have been written in C */
/* ------------------------------------------------------------ */
typedef struct
{
long x;
long y;
} T_cart;
generic main()
{
stream T_cart[N] A;
stream T_cart[N] B;
genera (output_stream A);
elabora (input_stream A output_stream B);
stampa (input_stream B);
}
genera (output_stream T_cart A[N]) {
Fgenera (output_stream A);
}
proc Fgenera (output_stream T_cart A[N])
inc<"stdio.h">
$c{
int i, k;
T_cart tmp_A[N];
// start message for regression test
printf ("STARTING gen\n");
for (k=0; k
$c{
int i;
static int count = 0;
static int ok = 0;
/*
for (i=0; i= MAX_ITER) {
// termination message for regression test
if (ok==0)
printf("ENDING with SUCCESS pipeline_C.ast\n");
else
printf("ENDING with FAILURE pipeline_C.ast\n");
}
}c$
proc Felab (in T_cart A[N] output_stream T_cart S[N])
inc<"stdio.h">
$c{
int i;
T_cart B[N];
for (i=0; i
====More complex examples of parmod usage====
===parmod.ast===
// -*- C++ -*-
#define N 10
#define M 5
generic main()
{
stream long A1;
stream long B1;
genera(output_stream A1);
p_array(input_stream A1 output_stream B1);
fine1(input_stream B1);
}
genera(output_stream long A1) {
fgen(output_stream A1);
}
proc fgen(output_stream long A1)
inc<"iostream">
$c++{
long a;
// start regression test
std::cerr << "STARTING gen" << std::endl;
for (int i=0;i
}
} while (true)
virtual_processors {
elab1 (in guard1 out B1) {
VP i {
f_p1 (in A1 output_stream B1);
}
}
}
output_section {
collects B1 from ANY Pv;
}
}
fine1(input_stream long B1)
inc<"iostream">
$c++{
static int count = 0;
static int ok = 0;
//std::cerr << "Fine -> ricevuto B1 = " << B1 <= N*M) {
if (ok==0)
std::cerr << "ENDING with SUCCESS fine parmod.ast" << std::endl;
else std::cerr << "ENDING with FAILURE fine parmod.ast" << std::endl;
}
}c++$
proc f_p1(in long A1 output_stream long B1)
inc<"iostream">
$c++{
long b = A1;
assist_out(B1,b);
}c++$
===parmod_due_proc.ast===
// -*- C++ -*-
#define CIPATH "/usr/include"
#define N 10
#define M 5
#define NUM1 0
#define NUM2 1
generic main()
{
stream long A;
stream long[2] B;
genera ( output_stream A);
p_array (input_stream A output_stream B);
fine1 (input_stream B);
}
genera(output_stream long A) {
fgen(output_stream A);
}
proc fgen(output_stream long A)
inc<"iostream">
$c++{
long a;
// start of regression test
std::cerr << "STARTING gen" << std::endl;
for (int i=0;i
$c++{
static int count = 0;
static int ok = 0;
long b;
if (B[1] != NUM2) ok = -1;
count++;
// end of regression test
if (count >= N*M) {
if (ok==0)
std::cerr << "ENDING with SUCCESS fine parmod_due_proc.ast" << std::endl;
else std::cerr << "ENDING with FAILURE fine parmod_due_proc.ast" << std::endl;
}
}c++$
proc f_p1(in long A, long i out long B[2])
inc<"iostream">
$c++{
B[0] = i;
B[1] = NUM1;
}c++$
proc f_p2(in long B1[2] out long B2[2])
inc<"iostream">
$c++{
B2[0] = B1[0];
B2[1] = NUM2;
}c++$
===nondeterminismo.ast===
// -*- C++ -*-
/* ------------------------------------------------------------ */
/* This example test nondeterministic receive over two streams */
/* in a parmod with none topology */
/* Program graph contains 2 sequential modules, a parmod and */
/* a further sequential. */
/* ------------------------------------------------------------ */
#define N 10
#define MAX_ITER1 10
#define MAX_ITER2 10
#define FILE_OUT "/tmp/risultato.txt"
typedef struct
{
long x;
long y;
} T_cart;
generic main()
{
stream T_cart[N] A;
stream long A1;
stream T_cart[N] B;
genera1 (output_stream A);
genera2 (output_stream A1);
elabora (input_stream A, A1 output_stream B);
stampa (input_stream B);
}
genera1(output_stream T_cart A[N]) {
Fgenera1(output_stream A);
}
proc Fgenera1(output_stream T_cart A[N])
inc<"iostream">
$c++{
T_cart tmp_A[N];
// start regression test
std::cerr << "STARTING fgen1" << std::endl;
for (int k=0; k
$c++{
static long c = 0;
// start regression test
std::cerr << "STARTING fgen2" << std::endl;
for(int k=0; k
$c++{
std::ofstream f;
static int file_aperto = -1;
static int count = 0;
static int ok = 0;
if (file_aperto == -1) {
f.open (FILE_OUT);
file_aperto = 0;
}
for(int i=0; i= MAX_ITER1) {
f.close();
// end of regression test
if (ok==0)
std::cerr << "ENDING with SUCCESS nondeterminismo.ast su file " << FILE_OUT << std::endl;
else
std::cerr << "ENDING with FAILURE nondeterminismo.ast su file " << FILE_OUT << std::endl;
}
}c++$
proc Felab1(in T_cart A[N] output_stream T_cart S[N])
inc<"iostream">
$c++{
int i;
T_cart B[N];
for(i=0; i
$c++{
}c++$
===array_scatter.ast===
// -*- C++ -*-
#define N 10
generic main()
{
stream long[N] A1;
stream long[N] A2;
stream long[N] B1;
stream long[N] B2;
genera1 (output_stream A1);
genera2 (output_stream A2);
cross (input_stream A1, A2 output_stream B1, B2);
fine1 (input_stream B1);
fine2 (input_stream B2);
}
genera1(output_stream long A1[N]) {
fgen1(output_stream A1);
}
proc fgen1(output_stream long A1[N])
inc<"iostream">
$c++{
long a[N];
// start regression test
std::cerr << "STARTING fgen1" << std::endl;
for (int i=0;i
$c++{
long a[N];
// start regression test
std::cerr << "STARTING fgen2" << std::endl;
for (int i=0;i;
collects s2 from ALL Pv[i] {
int el2;
int B2_[N];
AST_FOR_EACH(el2) {
B2_[i]=el2;
}
assist_out (B2, B2_);
}<>;
}
}
fine1(input_stream long B1[N])
inc<"iostream">
$c++{
int ok = 0;
/*
std::cerr << "Fine1: " << std::endl;
for (int i=0; i
$c++{
int ok = 0;
/*
std::cerr << "Fine2: " << std::endl;
for (int i=0; i
$c++{
long b;
b = A1;
B1 = b;
}c++$
proc f_p2(in long A2 out long B2)
inc<"iostream">
$c++{
B2 = A2;
}c++$
===array_on_demand_attrib_array_replic.ast===
// -*- C++ -*-
#define N 5
#define M 10
#define MAX_ITER 20
#define RIS "/tmp/risultato.txt"
/***************************************************************/
/* */
/* Test of the on_demand distribution over the array topology */
/* */
/* The parmod "elabora" has array topology */
/* */
/* The replicated attribute is a one-dimension array */
/* */
/**************************************************************/
generic main() {
stream long[M] A;
stream long[M] B;
genera (output_stream A);
elabora (input_stream A output_stream B);
stampa (input_stream B);
}
genera (output_stream long A[M]) {
Fgenera (output_stream A);
}
proc Fgenera (output_stream long A[M])
inc<"iostream">
$c++{
long tmp_A[M];
// start regression test
std::cerr << "STARTING fgen" << std::endl;
for (int k=0; k;
}
}
stampa (input_stream long B[M])
inc<"fstream","iostream">
$c++{
static std::ofstream f;
static int count = 0;
static int ok = 0;
if (count == 0) {
f.open (RIS);
}
/* print and verify results */
for (int i=0; i= MAX_ITER) {
if (ok==0)
std::cerr << "ENDING with SUCCESS fine array_on_demand_attrib_array_replic.ast" << std::endl;
else std::cerr << "ENDING with FAILURE fine array_on_demand_attrib_array_replic.ast" << std::endl;
f.close();
}
}c++$
proc Felab (in long A[M] out long B_[M])
inc<"iostream">
$c++{
for (int i=0; i