magistraleinformaticanetworking:spd:assistexamples
Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
Entrambe le parti precedenti la revisioneRevisione precedente | |||
magistraleinformaticanetworking:spd:assistexamples [19/05/2010 alle 12:48 (15 anni fa)] – 3 more examples added Massimo Coppola | magistraleinformaticanetworking:spd:assistexamples [19/05/2010 alle 12:52 (15 anni fa)] (versione attuale) – Massimo Coppola | ||
---|---|---|---|
Linea 908: | Linea 908: | ||
===array_scatter.ast=== | ===array_scatter.ast=== | ||
<file - array_scatter.ast> | <file - 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 | ||
+ | genera2 | ||
+ | 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<" | ||
+ | $c++{ | ||
+ | long a[N]; | ||
+ | | ||
+ | // start regression test | ||
+ | std::cerr << " | ||
+ | |||
+ | for (int i=0; | ||
+ | a[i] = i; | ||
+ | | ||
+ | assist_out(A1, | ||
+ | }c++$ | ||
+ | |||
+ | |||
+ | genera2(output_stream long A2[N]) { | ||
+ | fgen2(output_stream A2); | ||
+ | } | ||
+ | |||
+ | |||
+ | proc fgen2(output_stream long A2[N]) | ||
+ | inc<" | ||
+ | $c++{ | ||
+ | long a[N]; | ||
+ | |||
+ | // start regression test | ||
+ | std::cerr << " | ||
+ | |||
+ | for (int i=0; | ||
+ | a[i] = 10 + i; | ||
+ | | ||
+ | assist_out(A2, | ||
+ | }c++$ | ||
+ | |||
+ | |||
+ | parmod cross(input_stream long A1[N], long A2[N] output_stream long B1[N], long B2[N]) { | ||
+ | |||
+ | topology array [i:N] Pv; | ||
+ | |||
+ | attribute long S[N] scatter S[*i0] onto Pv[i0]; | ||
+ | |||
+ | stream long s1; | ||
+ | stream long s2; | ||
+ | |||
+ | do input_section { | ||
+ | guard1: on , , A1 { | ||
+ | distribution A1[*j] scatter to S[j]; | ||
+ | } | ||
+ | guard2: on , , A2 { | ||
+ | distribution A2[*k] scatter to S[k]; | ||
+ | } | ||
+ | } while (true) | ||
+ | | ||
+ | virtual_processors { | ||
+ | elab1(in guard1 out s1) { | ||
+ | VP i { | ||
+ | f_p1(in S[i] out s1); | ||
+ | } | ||
+ | } | ||
+ | elab2(in guard2 out s2) { | ||
+ | VP i { | ||
+ | f_p2(in S[i] out s2); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | output_section { | ||
+ | collects s1 from ALL Pv[i] { | ||
+ | int el1; | ||
+ | int B1_[N]; | ||
+ | AST_FOR_EACH(el1) { | ||
+ | B1_[i]=el1; | ||
+ | } | ||
+ | assist_out (B1, B1_); | ||
+ | }<>; | ||
+ | |||
+ | 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<" | ||
+ | $c++{ | ||
+ | int ok = 0; | ||
+ | | ||
+ | /* | ||
+ | std::cerr << " | ||
+ | for (int i=0; i<N; i++) | ||
+ | std::cerr << B1[i] << " "; | ||
+ | std::cerr << std::endl; | ||
+ | */ | ||
+ | | ||
+ | for (int i=0; | ||
+ | if (ok==0) | ||
+ | std::cerr << " | ||
+ | else | ||
+ | std::cerr << " | ||
+ | }c++$ | ||
+ | |||
+ | |||
+ | fine2(input_stream long B2[N]) | ||
+ | |||
+ | inc<" | ||
+ | $c++{ | ||
+ | int ok = 0; | ||
+ | |||
+ | /* | ||
+ | std::cerr << " | ||
+ | for (int i=0; i<N; i++) | ||
+ | std::cerr << B2[i] << " "; | ||
+ | std::cerr << std::endl; | ||
+ | */ | ||
+ | |||
+ | for (int i=0; | ||
+ | if (ok==0) | ||
+ | std::cerr << " | ||
+ | else | ||
+ | std::cerr << " | ||
+ | }c++$ | ||
+ | |||
+ | |||
+ | proc f_p1(in long A1 out long B1) | ||
+ | |||
+ | inc<" | ||
+ | $c++{ | ||
+ | long b; | ||
+ | b = A1; | ||
+ | B1 = b; | ||
+ | }c++$ | ||
+ | |||
+ | |||
+ | proc f_p2(in long A2 out long B2) | ||
+ | |||
+ | inc<" | ||
+ | $c++{ | ||
+ | B2 = A2; | ||
+ | }c++$ | ||
</ | </ | ||
===array_on_demand_attrib_array_replic.ast=== | ===array_on_demand_attrib_array_replic.ast=== | ||
<file - array_on_demand_attrib_array_replic.ast> | <file - array_on_demand_attrib_array_replic.ast> | ||
+ | // -*- C++ -*- | ||
+ | #define N 5 | ||
+ | #define M 10 | ||
+ | #define MAX_ITER 20 | ||
+ | #define RIS "/ | ||
+ | |||
+ | / | ||
+ | /* */ | ||
+ | /* Test of the on_demand distribution over the array topology | ||
+ | /* */ | ||
+ | /* The parmod " | ||
+ | /* */ | ||
+ | /* The replicated attribute is a one-dimension array */ | ||
+ | /* */ | ||
+ | / | ||
+ | |||
+ | generic main() { | ||
+ | stream long[M] A; | ||
+ | stream long[M] B; | ||
+ | |||
+ | genera | ||
+ | elabora | ||
+ | stampa | ||
+ | } | ||
+ | |||
+ | |||
+ | genera (output_stream long A[M]) { | ||
+ | Fgenera (output_stream A); | ||
+ | } | ||
+ | |||
+ | |||
+ | proc Fgenera (output_stream long A[M]) | ||
+ | inc<" | ||
+ | $c++{ | ||
+ | long tmp_A[M]; | ||
+ | |||
+ | // start regression test | ||
+ | std::cerr << " | ||
+ | | ||
+ | for (int k=0; k< | ||
+ | for (int i=0; i<M; i++) | ||
+ | tmp_A[i] = i; | ||
+ | assist_out (A, tmp_A); | ||
+ | } | ||
+ | }c++$ | ||
+ | |||
+ | |||
+ | parmod elabora (input_stream long A[M] output_stream long B[M]) { | ||
+ | |||
+ | topology array [i:N] Pv; | ||
+ | |||
+ | /* bug in module builder solved: | ||
+ | it was taking B_ as an integer, while it is an array */ | ||
+ | |||
+ | attribute long B_[M] replicated; | ||
+ | stream long ris[M]; | ||
+ | | ||
+ | do input_section { | ||
+ | guard1: on , , A { | ||
+ | distribution A on_demand to Pv; | ||
+ | } | ||
+ | } while (true) | ||
+ | |||
+ | virtual_processors { | ||
+ | elab (in guard1 out ris) { | ||
+ | VP i { | ||
+ | Felab (in A out B_); | ||
+ | assist_out (ris, B_); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | output_section { | ||
+ | collects ris from ANY Pv { | ||
+ | assist_out(B, | ||
+ | }<>; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | stampa (input_stream long B[M]) | ||
+ | |||
+ | inc<" | ||
+ | $c++{ | ||
+ | static std:: | ||
+ | static int count = 0; | ||
+ | static int ok = 0; | ||
+ | |||
+ | if (count == 0) { | ||
+ | f.open (RIS); | ||
+ | } | ||
+ | |||
+ | /* print and verify results */ | ||
+ | for (int i=0; i<M; i++) { | ||
+ | f << B[i] << std::endl; | ||
+ | if (B[i] != i) ok = -1; | ||
+ | } | ||
+ | count++; | ||
+ | | ||
+ | // end of regression test | ||
+ | if (count >= MAX_ITER) { | ||
+ | if (ok==0) | ||
+ | std::cerr << " | ||
+ | else std::cerr << " | ||
+ | f.close(); | ||
+ | } | ||
+ | }c++$ | ||
+ | |||
+ | |||
+ | proc Felab (in long A[M] out long B_[M]) | ||
+ | |||
+ | inc<" | ||
+ | $c++{ | ||
+ | for (int i=0; i<M; i++) | ||
+ | B_[i] = A[i]; | ||
+ | }c++$ | ||
</ | </ | ||
magistraleinformaticanetworking/spd/assistexamples.1274273291.txt.gz · Ultima modifica: 19/05/2010 alle 12:48 (15 anni fa) da Massimo Coppola