summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cilk-plus/cilk_keywords_test/compile/c++-cilk-for.cc
blob: 73fbe9fe147b9fc46f5385a9778ef63a1c8d6fe2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#if HAVE_IO
#include <iostream> 
#include <cstdio>
#endif
#include <cstring>

#include <cilk/cilk.h>  
#define NUMBER 50
using namespace std;

class CClass {
private: 
  int x[NUMBER],y[NUMBER],r[NUMBER];
public:
  void PrintValues();
  CClass (int, int);

#if 1
  int SomeCalc();
  ~CClass ();
  virtual int some_function(int a, int b) {}; 
#endif

};

CClass::CClass(int a, int b) 
{
  cilk_for (int ii = 0; ii < NUMBER; ++ii) {
    x[ii]=5;
    y[ii]=9;
    r[ii]=33;
  }
}
#if 1
CClass::~CClass() 
{
#if 1
  _Cilk_for (int ii = 0; ii < NUMBER; ii++) {
    x[ii]=0;
    y[ii]=0;
    r[ii]=0;
  }
#endif
}

int CClass::SomeCalc()
{
  cilk_for (int jj = 0;jj  < NUMBER; jj++) {
    r[jj] = x[jj] * y[jj];
  }
  
  return (r[9]+r[8]+r[7]+r[6]+r[5]+r[4]+r[3]+r[2]+r[1]+r[0]);
}
#endif 
void CClass::PrintValues()
{
  for(int ii = 0; ii < NUMBER; ii++)
  {
#if HAVE_IO
    printf("X[%2d]=%2d Y[%2d]=%2d r[%2d]=%3d\n",ii,x[ii],ii,y[ii],ii,r[ii]); 
#endif
  }
  return;
}

int main(void) 
{
  CClass vars(5,9);
  
#if HAVE_IO
  cout << "Array values BEFORE The Calculation: " << endl;
#endif
  vars.PrintValues();
  
  vars.SomeCalc();  


#if HAVE_IO
  cout << "Array values AFTER The Calculation: " << endl;
#endif
  vars.PrintValues();
  return 5;
}