magistraleinformaticanetworking:spm:skepu_sample
Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
Entrambe le parti precedenti la revisioneRevisione precedente | |||
magistraleinformaticanetworking:spm:skepu_sample [11/05/2012 alle 12:57 (13 anni fa)] – Marco Danelutto | magistraleinformaticanetworking:spm:skepu_sample [11/05/2012 alle 13:00 (13 anni fa)] (versione attuale) – Marco Danelutto | ||
---|---|---|---|
Linea 97: | Linea 97: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | === Sample reduce ==== | ||
+ | <code lang=" | ||
+ | #include < | ||
+ | |||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | // definition of functions to be used in the map and reduce | ||
+ | |||
+ | UNARY_FUNC(inc, | ||
+ | UNARY_FUNC(dec, | ||
+ | UNARY_FUNC(sq, | ||
+ | BINARY_FUNC(add, | ||
+ | BINARY_FUNC(sub, | ||
+ | BINARY_FUNC(mul, | ||
+ | BINARY_FUNC(div, | ||
+ | |||
+ | #define N 4 | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | // declare vectors | ||
+ | skepu:: | ||
+ | skepu:: | ||
+ | | ||
+ | // initialize the vector(s) to some meaningful value | ||
+ | for(int i=0; i<N;i++) { | ||
+ | v0[i]=i+1; | ||
+ | } | ||
+ | cout << " | ||
+ | for(int i=0; i<N; i++) | ||
+ | for(int j=0; j<N; j++) | ||
+ | m(i,j) = (i*N)+j; | ||
+ | cout << " | ||
+ | | ||
+ | skepu:: | ||
+ | int i = reduceadd(v0); | ||
+ | cout << "After reduceadd : " << i << endl; | ||
+ | |||
+ | skepu:: | ||
+ | i = reduceaddmat(m); | ||
+ | cout << "After reduceaddmat : " << i << endl; | ||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === Sample stencil (mapoverlap) ==== | ||
+ | <code lang=" | ||
+ | #include < | ||
+ | |||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | OVERLAP_FUNC(avg, | ||
+ | |||
+ | #define N 8 | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | // declare vectors | ||
+ | skepu:: | ||
+ | skepu:: | ||
+ | | ||
+ | // initialize the vector(s) to some meaningful value | ||
+ | for(int i=0; i<N;i++) { | ||
+ | v0[i]=i; | ||
+ | } | ||
+ | cout << " | ||
+ | | ||
+ | // compute things in stencil map mode | ||
+ | skepu:: | ||
+ | // in vecs, missing boundary filled with 1 (CONSTANT) | ||
+ | average(v0, | ||
+ | cout << "After average (boundary = 1): " << v2 << endl; | ||
+ | // consider the vector as a torus | ||
+ | average(v0, | ||
+ | cout << "After average (cyclic): | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === Sample maparray ==== | ||
+ | <code lang=" | ||
+ | #include < | ||
+ | |||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | // definition of functions to be used in the map and reduce | ||
+ | |||
+ | #define N 4 | ||
+ | |||
+ | ARRAY_FUNC(f, | ||
+ | { int s = 0; \ | ||
+ | | ||
+ | s += a[i]; \ | ||
+ | } \ | ||
+ | | ||
+ | | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | // declare vectors | ||
+ | skepu:: | ||
+ | skepu:: | ||
+ | skepu:: | ||
+ | | ||
+ | // initialize the vector(s) to some meaningful value | ||
+ | for(int i=0; i<N;i++) { | ||
+ | v0[i]=i+1; | ||
+ | v1[i]=i; | ||
+ | } | ||
+ | cout << " | ||
+ | cout << " | ||
+ | | ||
+ | skepu:: | ||
+ | ff(v0, | ||
+ | cout << "After ff: " << v2 << endl; | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === Sample scan ==== | ||
+ | <code lang=" | ||
+ | #include < | ||
+ | |||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | // definition of functions to be used in the map and reduce | ||
+ | |||
+ | BINARY_FUNC(add, | ||
+ | BINARY_FUNC(mul, | ||
+ | |||
+ | #define N 4 | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | // declare vectors | ||
+ | skepu:: | ||
+ | skepu:: | ||
+ | skepu:: | ||
+ | | ||
+ | // initialize the vector(s) to some meaningful value | ||
+ | for(int i=0; i<N;i++) { | ||
+ | v0[i]=i+1; | ||
+ | v1[i]=-(i+1); | ||
+ | } | ||
+ | cout << " | ||
+ | | ||
+ | // one input map: forall i compute f(v0[i]) | ||
+ | skepu:: | ||
+ | // at pos i sum of items up to (i) | ||
+ | scanadd(v0, | ||
+ | cout << "After scanadd: " << v2 << endl; | ||
+ | // at pos i sum of items up to (i-1) | ||
+ | scanadd(v0, | ||
+ | cout << "After scanadd: " << v2 << endl; | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ |
magistraleinformaticanetworking/spm/skepu_sample.1336741057.txt.gz · Ultima modifica: 11/05/2012 alle 12:57 (13 anni fa) da Marco Danelutto