1 #include "primitiveFields.H"
11 Info<< "Initialising fields" << endl;
13 const label nIter = 100;
14 const label size = 10000000;
15 const label rndAddrSkip = 40;
16 const label redFac = 6;
17 const label redSize = size/redFac;
20 double* f1 = new double[size];
21 double* f2 = new double[size];
22 double* f3 = new double[size];
23 double* f4 = new double[size];
24 double* fr = new double[redSize];
25 label* addr = new label[size];
26 label* redAddr = new label[size];
27 label* redAddr2 = new label[size];
29 for (register label i=0; i<size; i++)
35 redAddr[i] = i/redFac;
36 redAddr2[i] = (size - i - 1)/redFac;
39 for (register label i=0; i<size; i+=rndAddrSkip)
41 addr[i] = genAddr.integer(0, size-1);
44 for (register label i=0; i<redSize; i++)
49 Info<< "Done\n" <<endl;
52 Info<< "Single loop combined operation (expression templates)"
55 cpuTime executionTime;
57 for (int j=0; j<nIter; j++)
59 for (register label i=0; i<size; i++)
61 f4[i] = f1[i] + f2[i] - f3[i];
65 Info<< "ExecutionTime = "
66 << executionTime.elapsedCpuTime()
69 Snull<< f4[1] << endl << endl;
73 Info<< "Single loop combined operation with indirect addressing"
76 cpuTime executionTime;
78 for (int j=0; j<nIter; j++)
80 for (register label i=0; i<size; i++)
82 f4[addr[i]] = f1[addr[i]] + f2[addr[i]] - f3[addr[i]];
86 Info<< "ExecutionTime = "
87 << executionTime.elapsedCpuTime()
90 Snull<< f4[1] << endl << endl;
94 Info<< "Single loop reduction operation"
97 cpuTime executionTime;
98 label redOffset = (size - 1)/redFac;
100 for (int j=0; j<nIter; j++)
102 for (register label i=0; i<size; i++)
106 fr[redOffset - j] -= f2[i];
110 Info<< "ExecutionTime = "
111 << executionTime.elapsedCpuTime()
114 Snull<< fr[1] << endl << endl;
118 Info<< "Single loop reduction operation with indirect addressing"
121 cpuTime executionTime;
123 for (int j=0; j<nIter; j++)
125 for (register label i=0; i<size; i++)
127 fr[redAddr[i]] += f1[i];
128 fr[redAddr2[i]] -= f2[i];
132 Info<< "ExecutionTime = "
133 << executionTime.elapsedCpuTime()
136 Snull<< fr[1] << endl << endl;
140 Info<< "Separate loops ?= operations" << endl;
142 cpuTime executionTime;
144 for (int j=0; j<nIter; j++)
146 for (register label i=0; i<size; i++)
150 for (register label i=0; i<size; i++)
154 for (register label i=0; i<size; i++)
160 Info<< "ExecutionTime = "
161 << executionTime.elapsedCpuTime()
164 Snull<< f4[1] << endl << endl;
168 Info<< "OpenFOAM field algebra" << endl;
176 cpuTime executionTime;
178 for (int j=0; j<nIter; j++)
180 //sf4 = sf1 + sf2 - sf3;
186 Info<< "ExecutionTime = "
187 << executionTime.elapsedCpuTime()
190 Snull<< sf4[1] << endl << endl;