| 1 |
|
|---|
| 2 | #ifndef _increment_hpp_
|
|---|
| 3 | #define _increment_hpp_
|
|---|
| 4 |
|
|---|
| 5 | #include "functions.h"
|
|---|
| 6 | #include "EnsembleVariables.hpp"
|
|---|
| 7 |
|
|---|
| 8 | #include <stdio.h>
|
|---|
| 9 | #include <stdlib.h>
|
|---|
| 10 | #include <iostream>
|
|---|
| 11 | #include <sstream>
|
|---|
| 12 |
|
|---|
| 13 | using namespace std;
|
|---|
| 14 |
|
|---|
| 15 | class Increment {
|
|---|
| 16 | int var_index;
|
|---|
| 17 | int nb_diff_CL;
|
|---|
| 18 | int cache_lines;
|
|---|
| 19 | int line_size;
|
|---|
| 20 | int proc_id;
|
|---|
| 21 | EnsembleVariables * E;
|
|---|
| 22 |
|
|---|
| 23 | public:
|
|---|
| 24 |
|
|---|
| 25 | Increment(int nb_diff_ML, int nb_diff_CL, int line_size, int cache_lines, EnsembleVariables * E, int proc_id) {
|
|---|
| 26 | this->nb_diff_CL = nb_diff_CL;
|
|---|
| 27 | this->line_size = line_size;
|
|---|
| 28 | this->cache_lines = cache_lines;
|
|---|
| 29 | this->E = E;
|
|---|
| 30 | this->proc_id = proc_id;
|
|---|
| 31 |
|
|---|
| 32 | const int nb_vars_proc = E->getVarCount(proc_id);
|
|---|
| 33 | int local_index = randint(0, nb_vars_proc - 1);
|
|---|
| 34 | var_index = 0;
|
|---|
| 35 | while (!E->isPublic(var_index) && !E->isPrivate(var_index,proc_id)) {
|
|---|
| 36 | var_index++;
|
|---|
| 37 | }
|
|---|
| 38 | for (int i = 0; i < local_index; i++) {
|
|---|
| 39 | var_index++;
|
|---|
| 40 | while (!E->isPublic(var_index) && !E->isPrivate(var_index,proc_id)) {
|
|---|
| 41 | var_index++;
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | ~Increment() {}
|
|---|
| 47 |
|
|---|
| 48 | string writeOutput() {
|
|---|
| 49 | stringstream res;
|
|---|
| 50 | int index = index2realindex(var_index, nb_diff_CL, cache_lines, line_size);
|
|---|
| 51 | if (E->isPublic(var_index)) {
|
|---|
| 52 | if (!E->isUnc(var_index)) {
|
|---|
| 53 | if (E->isRW(var_index)) {
|
|---|
| 54 | res << " pthread_spin_lock(&lock_tab[" << var_index << "]);" << endl;
|
|---|
| 55 | res << " tab[" << index << "]++;" << endl;
|
|---|
| 56 | res << " pthread_spin_unlock(&lock_tab[" << var_index << "]);" << endl;
|
|---|
| 57 | }
|
|---|
| 58 | else if (E->isRO(var_index)) {
|
|---|
| 59 | res << " local_var = tab[" << index << "];" << endl;
|
|---|
| 60 | }
|
|---|
| 61 | else {
|
|---|
| 62 | assert(E->isWO(var_index));
|
|---|
| 63 | res << " tab[" << index << "] = 1;" << endl;
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 | else {
|
|---|
| 67 | if (E->isRW(var_index)) {
|
|---|
| 68 | res << " rd_wr_unc(" << index << ");" << endl;
|
|---|
| 69 | }
|
|---|
| 70 | else if (E->isRO(var_index)) {
|
|---|
| 71 | res << " rd_unc(" << index << ");" << endl;
|
|---|
| 72 | }
|
|---|
| 73 | else {
|
|---|
| 74 | assert(E->isWO(var_index));
|
|---|
| 75 | res << " wr_unc(" << index << ");" << endl;
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 | else {
|
|---|
| 80 | assert(E->isPrivate(var_index,proc_id));
|
|---|
| 81 | if (!E->isUnc(var_index)) {
|
|---|
| 82 | if (E->isRW(var_index)) {
|
|---|
| 83 | res << " tab[" << index << "]++; // variable privee au proc " << proc_id << endl;
|
|---|
| 84 | }
|
|---|
| 85 | else if (E->isRO(var_index)) {
|
|---|
| 86 | res << " local_var = tab[" << index << "]; // variable privee au proc " << proc_id << " et en RO" << endl;
|
|---|
| 87 | }
|
|---|
| 88 | else {
|
|---|
| 89 | assert(E->isWO(var_index));
|
|---|
| 90 | res << " tab[" << index << "] = 1; // variable privee au proc " << proc_id << " et en WO" << endl;
|
|---|
| 91 | }
|
|---|
| 92 | }
|
|---|
| 93 | else {
|
|---|
| 94 | if (E->isRW(var_index)) {
|
|---|
| 95 | res << " // Variable privee au proc " << proc_id << endl;
|
|---|
| 96 | res << " rd_wr_unc(" << index << ");" << endl;
|
|---|
| 97 | }
|
|---|
| 98 | else if (E->isRO(var_index)) {
|
|---|
| 99 | res << " // Variable privee au proc " << proc_id << " et en RO" << endl;
|
|---|
| 100 | res << " rd_unc(" << index << ");" << endl;
|
|---|
| 101 | }
|
|---|
| 102 | else {
|
|---|
| 103 | assert(E->isWO(var_index));
|
|---|
| 104 | res << " // Variable privee au proc " << proc_id << " et en WO" << endl;
|
|---|
| 105 | res << " wr_unc(" << index << ");" << endl;
|
|---|
| 106 | }
|
|---|
| 107 | }
|
|---|
| 108 | }
|
|---|
| 109 | return res.str();
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | };
|
|---|
| 113 |
|
|---|
| 114 | #endif
|
|---|
| 115 |
|
|---|