File: stenciln.cpp

package info (click to toggle)
blitz%2B%2B 1%3A0.10-3.2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,276 kB
  • ctags: 12,037
  • sloc: cpp: 70,465; sh: 11,116; fortran: 1,510; python: 1,246; f90: 852; makefile: 701
file content (61 lines) | stat: -rw-r--r-- 1,360 bytes parent folder | download | duplicates (7)
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
#include <blitz/array.h>
#include <blitz/timer.h>

BZ_USING_NAMESPACE(blitz)

BZ_DECLARE_STENCIL4(acoustic2D_stencil,P1,P2,P3,c)
  P3 = 2 * P2 + c * Laplacian2D(P2) - P1;
BZ_END_STENCIL

int benchmark(int N, int nIterations, int blockSize)
{
    Array<float,2> P1, P2, P3, c;
    allocateArrays(shape(N,N), P1, P2, P3, c);

    // Initial conditions: obviously in a real application these
    // wouldn't be zeroed...
    Range I(0,blockSize-1), J(0,blockSize-1);

    P1(I,J) = 0;
    P2(I,J) = 0;
    P3(I,J) = 0;
    c(I,J) = 0;

    for (int i=0; i < nIterations; ++i)
    {
        // Apply the stencil object to the arrays
        applyStencil(acoustic2D_stencil(), P1(I,J), P2(I,J), P3(I,J), c(I,J));

        // Set [P1,P2,P3] <- [P2,P3,P1] to set up for the next
        // time step
        cycleArrays(P1,P2,P3);
    }

    return 0;
}

int main()
{
    Timer timer;

    cout << "N\tMflops" << endl;

    const int blockSize = 27;

    for (int N=2000; N < 2100; ++N)
    {
        double stencilPoints = pow(blockSize-2,2.0);
        int nIterations = 5000;

        timer.start();
        benchmark(N, nIterations, blockSize);
        timer.stop();

        double flops = (4 + 7) * stencilPoints * nIterations;
        double Mflops = flops / timer.elapsedSeconds() / 1.0E+6;
        cout << N << "\t" << Mflops << endl;
    }

    return 0;
}