Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
magistraleinformaticanetworking:spm:spm1213_c_ff_false_sharing_fs3 [16/04/2013 alle 16:07 (11 anni fa)] Marco Danelutto creata |
magistraleinformaticanetworking:spm:spm1213_c_ff_false_sharing_fs3 [16/04/2013 alle 16:08 (11 anni fa)] (versione attuale) Marco Danelutto |
||
---|---|---|---|
Linea 2: | Linea 2: | ||
#include < | #include < | ||
#include < | #include < | ||
+ | #include < | ||
#include < | #include < | ||
Linea 7: | Linea 8: | ||
using namespace ff; | using namespace ff; | ||
using namespace std; | using namespace std; | ||
- | |||
- | int n; | ||
- | float ** mat; | ||
- | float * vec; | ||
typedef struct __task { | typedef struct __task { | ||
Linea 17: | Linea 14: | ||
int | int | ||
} TASK; | } TASK; | ||
+ | |||
+ | typedef union __res { | ||
+ | float x; | ||
+ | float pad[16]; | ||
+ | } RES; | ||
+ | |||
+ | int n; | ||
+ | float ** mat; | ||
+ | RES * vec; | ||
class Emitter : public ff_node { | class Emitter : public ff_node { | ||
Linea 44: | Linea 50: | ||
class Worker : public ff_node { | class Worker : public ff_node { | ||
private: | private: | ||
- | int wid; | + | int wid; |
- | + | public: | |
- | public: | + | |
Worker(int i):wid(i) {} | Worker(int i):wid(i) {} | ||
Linea 52: | Linea 57: | ||
TASK * task = (TASK *) t; | TASK * task = (TASK *) t; | ||
- | // cout << " | ||
// cout << " | // cout << " | ||
struct timespec t0, t1; | struct timespec t0, t1; | ||
Linea 58: | Linea 62: | ||
for(int i=task-> | for(int i=task-> | ||
for(int j=0; j<n; j++) | for(int j=0; j<n; j++) | ||
- | vec[wid] += mat[i][j]; | + | vec[wid].x += mat[i][j]; |
} | } | ||
clock_gettime(CLOCK_THREAD_CPUTIME_ID,& | clock_gettime(CLOCK_THREAD_CPUTIME_ID,& | ||
Linea 76: | Linea 80: | ||
int ck = atoi(argv[3]); | int ck = atoi(argv[3]); | ||
int nw = atoi(argv[4]); | int nw = atoi(argv[4]); | ||
+ | |||
+ | cout << "Float is " << sizeof(float) << " bytes " << endl; | ||
// cout << "Init 1" << endl; | // cout << "Init 1" << endl; | ||
Linea 89: | Linea 95: | ||
// cout << "Init 3" << endl; | // cout << "Init 3" << endl; | ||
- | vec = new float[nw]; | + | vec = new RES[nw]; |
for(int i=0; i<nw; i++) | for(int i=0; i<nw; i++) | ||
- | vec[i] = 0.0; | + | vec[i].x = 0.0; |
// cout << " | // cout << " | ||
Linea 108: | Linea 114: | ||
float sum = 0.0; | float sum = 0.0; | ||
for(int i=0; i<nw; i++) | for(int i=0; i<nw; i++) | ||
- | sum += vec[i]; | + | sum += vec[i].x; |
farm.ffStats(cerr); | farm.ffStats(cerr); | ||
Linea 116: | Linea 122: | ||
} | } | ||
+ | |||
</ | </ |