/*      TESTING OF THE OWN CALCULASHION
        FOR DISTRIBUTED ARRAY A[N][M][K][L].
*/

#include <math.h>
#include <stdlib.h>
#include <stdio.h>

#define N 32
#define M 32
#define K 32
#define L 32
#define NL 1000

static void owncal4101();
static void owncal4102();
static void owncal4103();
static void owncal4104();
static void owncal4105();
static void owncal4106();
static void owncal4107();
static void owncal4108();
static void owncal4109();
static void owncal4110();

static void serial4(int AR[][M][K][L], int NN, int NM, int NK, int NLL, int NNL);
static void ansyes(const char tname[]);
static void ansno(const char tname[]);

int main(int argc, char *argv[])
{
    printf("===START OF OWNCAL41========================\n");
    owncal4101();
    owncal4102();
    owncal4103();
    owncal4104();
    owncal4105();
    owncal4106();
    owncal4107();
    owncal4108();
    owncal4109();
    owncal4110();

    printf("=== END OF OWNCAL41 ========================= \n");
    return 0;
}
/* ---------------------------------------------OWNCAL4101  */
void owncal4101()
{
    int C[N][M][K][L];
    char tname[] = "OWN4101";
    int i, j, ii, jj, NN, NM, NK, NLL, NNL;
    int nloopi, nloopj, nloopii, nloopjj;

    #pragma dvm array distribute[block][block][block][block]
    int A[N][M][K][L];

    NN = N;
    NM = M;
    NK = K;
    NLL = L;
    NNL = NL;

    serial4(C, NN, NM, NK, NLL, NNL);

    nloopi = NL;
    nloopj = NL;
    nloopii = NL;
    nloopjj = NL;

    #pragma dvm region out(A)
    {
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            for (ii = 0; ii < K; ii++)
                for (jj = 0; jj < L; jj++)
                    A[i][j][ii][jj] = NL + i + j + ii + jj;
    } /*end region*/

    #pragma dvm get_actual(A)

    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj]) reduction(min(nloopi), min(nloopj), min(nloopii), min(nloopjj))
    for (i = 1; i < N - 1; i++)
        for (j = 1; j < M - 1; j++)
            for (ii = 1; ii < K - 1; ii++)
                for (jj = 1; jj < L - 1; jj++)
                    if (A[i][j][ii][jj] != C[i][j][ii][jj]) {
                        if (nloopi > i) nloopi = i;
                        if (nloopj > j) nloopj = j;
                        if (nloopii > ii) nloopii = ii;
                        if (nloopjj > jj) nloopjj = jj;
                    }
    if (nloopi == NL && nloopj == NL && nloopii == NL && nloopjj == NL)
        ansyes(tname);
    else
        ansno(tname);
}

/* ---------------------------------------------OWNCAL4102  */
void owncal4102()
{
    int C[N][M][K][L];
    char tname[] = "OWN4102";
    int i, j, ii, jj, NN, NM, NK, NLL, NNL;
    int nloopi, nloopj, nloopii, nloopjj;

    #pragma dvm array distribute[block][block][block][block]
    int A[N][M][K][L];

    NN = N;
    NM = M;
    NK = K;
    NLL = L;
    NNL = NL;

    serial4(C, NN, NM, NK, NLL, NNL);
    C[0][0][0][0] = N + M + K + L + NL + 2;
    nloopi = NL;
    nloopj = NL;
    nloopii = NL;
    nloopjj = NL;

    #pragma dvm region out(A)
    {
    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            for (ii = 0; ii < K; ii++)
                for (jj = 0; jj < L; jj++)
                    A[i][j][ii][jj] = NL + i + j + ii + jj;

    A[0][0][0][0] = N + M + K + L + NL + 2;

    } /*end region*/

    #pragma dvm get_actual(A)

    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj]) reduction(min(nloopi), min(nloopj), min(nloopii), min(nloopjj))
    for (i = 1; i < N - 1; i++)
        for (j = 1; j < M - 1; j++)
            for (ii = 1; ii < K - 1; ii++)
                for (jj = 1; jj < L - 1; jj++)
                    if (A[i][j][ii][jj] != C[i][j][ii][jj]) {
                        if (nloopi > i) nloopi = i;
                        if (nloopj > j) nloopj = j;
                        if (nloopii > ii) nloopii = ii;
                        if (nloopjj > jj) nloopjj = jj;
                    }
    if (nloopi == NL && nloopj == NL && nloopii == NL && nloopjj == NL)
        ansyes(tname);
    else
        ansno(tname);
}

/* ---------------------------------------------OWNCAL4103  */
void owncal4103()
{
    int C[N][M][K][L];
    char tname[] = "OWN4103";
    int i, j, ii, jj, NN, NM, NK, NLL, NNL;
    int nloopi, nloopj, nloopii, nloopjj;
    int ni, nj, nii, njj;

    #pragma dvm array distribute[block][block][block][block]
    int A[N][M][K][L];

    NN = N;
    NM = M;
    NK = K;
    NLL = L;
    NNL = NL;

    serial4(C, NN, NM, NK, NLL, NNL);
    ni = N / 2;
    nj = M / 2;
    nii = K / 2;
    njj = L / 2;

    C[ni][nj][nii][njj] = N + M + K + L + NL + 3;
    nloopi = NL;
    nloopj = NL;
    nloopii = NL;
    nloopjj = NL;

    #pragma dvm actual(ni, nj, nii, njj)
    #pragma dvm region out(A), in(ni, nj, nii, njj)
    {
    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            for (ii = 0; ii < K; ii++)
                for (jj = 0; jj < L; jj++)
                    A[i][j][ii][jj] = NL + i + j + ii + jj;

    A[ni][nj][nii][njj] = N + M + K + L + NL + 3;

    } /*end region*/

    #pragma dvm get_actual(A)

    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj]) reduction(min(nloopi), min(nloopj), min(nloopii), min(nloopjj))
    for (i = 1; i < N - 1; i++)
        for (j = 1; j < M - 1; j++)
            for (ii = 1; ii < K - 1; ii++)
                for (jj = 1; jj < L - 1; jj++)
                    if (A[i][j][ii][jj] != C[i][j][ii][jj]) {
                        if (nloopi > i) nloopi = i;
                        if (nloopj > j) nloopj = j;
                        if (nloopii > ii) nloopii = ii;
                        if (nloopjj > jj) nloopjj = jj;
                    }
    if (nloopi == NL && nloopj == NL && nloopii == NL && nloopjj == NL)
        ansyes(tname);
    else
        ansno(tname);
}

/* ---------------------------------------------OWNCAL4104  */
void owncal4104()
{
    int C[N][M][K][L];
    char tname[] = "OWN4104";
    int i, j, ii, jj, NN, NM, NK, NLL, NNL;
    int nloopi, nloopj, nloopii, nloopjj;
    int ni, nj, nii, njj;

    #pragma dvm array distribute[block][block][block][block]
    int A[N][M][K][L];

    NN = N;
    NM = M;
    NK = K;
    NLL = L;
    NNL = NL;

    serial4(C, NN, NM, NK, NLL, NNL);
    ni = N / 2;
    nj = M / 2;
    nii = K / 2;
    njj = L / 2;

    C[ni + 1][nj + 1][nii + 1][njj + 1] = N + M + K + L + NL + 4;
    nloopi = NL;
    nloopj = NL;
    nloopii = NL;
    nloopjj = NL;

    #pragma dvm actual(ni, nj, nii, njj)
    #pragma dvm region out(A), in(ni, nj, nii, njj)
    {
    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            for (ii = 0; ii < K; ii++)
                for (jj = 0; jj < L; jj++)
                    A[i][j][ii][jj] = NL + i + j + ii + jj;

    A[ni + 1][nj + 1][nii + 1][njj + 1] = N + M + K + L + NL + 4;

    } /*end region*/

    #pragma dvm get_actual(A)

    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj]) reduction(min(nloopi), min(nloopj), min(nloopii), min(nloopjj))
    for (i = 1; i < N - 1; i++)
        for (j = 1; j < M - 1; j++)
            for (ii = 1; ii < K - 1; ii++)
                for (jj = 1; jj < L - 1; jj++)
                    if (A[i][j][ii][jj] != C[i][j][ii][jj]) {
                        if (nloopi > i) nloopi = i;
                        if (nloopj > j) nloopj = j;
                        if (nloopii > ii) nloopii = ii;
                        if (nloopjj > jj) nloopjj = jj;
                    }
    if (nloopi == NL && nloopj == NL && nloopii == NL && nloopjj == NL)
        ansyes(tname);
    else
        ansno(tname);
}


/* ---------------------------------------------OWNCAL4105  */
void owncal4105()
{
    int C[N][M][K][L];
    char tname[] = "OWN4105";
    int i, j, ii, jj, NN, NM, NK, NLL, NNL;
    int nloopi, nloopj, nloopii, nloopjj;
    int ni, nj, nii, njj;

    #pragma dvm array distribute[block][block][block][block]
    int A[N][M][K][L];

    NN = N;
    NM = M;
    NK = K;
    NLL = L;
    NNL = NL;

    serial4(C, NN, NM, NK, NLL, NNL);
    ni = N / 2;
    nj = M / 2;
    nii = K / 2;
    njj = L / 2;

    C[ni - 1][nj - 1][nii - 1][njj - 1] = -(N + M + K + L + NL + 5);
    nloopi = NL;
    nloopj = NL;
    nloopii = NL;
    nloopjj = NL;

    #pragma dvm actual(ni, nj, nii, njj)
    #pragma dvm region out(A), in(ni, nj, nii, njj)
    {
    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            for (ii = 0; ii < K; ii++)
                for (jj = 0; jj < L; jj++)
                    A[i][j][ii][jj] = NL + i + j + ii + jj;

    A[ni - 1][nj - 1][nii - 1][njj - 1] = -(N + M + K + L + NL + 5);

    } /*end region*/

    #pragma dvm get_actual(A)

    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj]) reduction(min(nloopi), min(nloopj), min(nloopii), min(nloopjj))
    for (i = 1; i < N - 1; i++)
        for (j = 1; j < M - 1; j++)
            for (ii = 1; ii < K - 1; ii++)
                for (jj = 1; jj < L - 1; jj++)
                    if (A[i][j][ii][jj] != C[i][j][ii][jj]) {
                        if (nloopi > i) nloopi = i;
                        if (nloopj > j) nloopj = j;
                        if (nloopii > ii) nloopii = ii;
                        if (nloopjj > jj) nloopjj = jj;
                    }
    if (nloopi == NL && nloopj == NL && nloopii == NL && nloopjj == NL)
        ansyes(tname);
    else
        ansno(tname);
}

/* ---------------------------------------------OWNCAL4106  */
void owncal4106()
{
    int C[N][M][K][L];
    char tname[] = "OWN4106";
    int i, j, ii, jj, NN, NM, NK, NLL, NNL;
    int nloopi, nloopj, nloopii, nloopjj;
    int ni, nj, nii, njj;

    #pragma dvm array distribute[block][block][block][block]
    int A[N][M][K][L];

    NN = N;
    NM = M;
    NK = K;
    NLL = L;
    NNL = NL;

    serial4(C, NN, NM, NK, NLL, NNL);
    ni = N / 2;
    nj = M / 2;
    nii = K / 2;
    njj = L / 2;

    C[ni - 1][nj + 1][nii - 1][njj + 1] = N + M + K + L + NL + 6;
    nloopi = NL;
    nloopj = NL;
    nloopii = NL;
    nloopjj = NL;

    #pragma dvm actual(ni, nj, nii, njj)
    #pragma dvm region out(A), in(ni, nj, nii, njj)
    {
    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            for (ii = 0; ii < K; ii++)
                for (jj = 0; jj < L; jj++)
                    A[i][j][ii][jj] = NL + i + j + ii + jj;

    A[ni - 1][nj + 1][nii - 1][njj + 1] = N + M + K + L + NL + 6;

    } /*end region*/

    #pragma dvm get_actual(A)

    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj]) reduction(min(nloopi), min(nloopj), min(nloopii), min(nloopjj))
    for (i = 1; i < N - 1; i++)
        for (j = 1; j < M - 1; j++)
            for (ii = 1; ii < K - 1; ii++)
                for (jj = 1; jj < L - 1; jj++)
                    if (A[i][j][ii][jj] != C[i][j][ii][jj]) {
                        if (nloopi > i) nloopi = i;
                        if (nloopj > j) nloopj = j;
                        if (nloopii > ii) nloopii = ii;
                        if (nloopjj > jj) nloopjj = jj;
                    }
    if (nloopi == NL && nloopj == NL && nloopii == NL && nloopjj == NL)
        ansyes(tname);
    else
        ansno(tname);
}
/* ---------------------------------------------OWNCAL4107  */
void owncal4107()
{
    int C[N][M][K][L];
    char tname[] = "OWN4107";
    int i, j, ii, jj, NN, NM, NK, NLL, NNL;
    int nloopi, nloopj, nloopii, nloopjj;
    int ni, nj, nii, njj;

    #pragma dvm array distribute[block][block][block][block]
    int A[N][M][K][L];

    NN = N;
    NM = M;
    NK = K;
    NLL = L;
    NNL = NL;

    serial4(C, NN, NM, NK, NLL, NNL);
    ni = N / 2;
    nj = M / 2;
    nii = K / 2;
    njj = L / 2;

    C[ni + 1][nj - 1][nii + 1][njj - 1] = N + M + K + L + NL + 7;
    nloopi = NL;
    nloopj = NL;
    nloopii = NL;
    nloopjj = NL;

    #pragma dvm actual(ni, nj, nii, njj)
    #pragma dvm region out(A), in(ni, nj, nii, njj)
    {
    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            for (ii = 0; ii < K; ii++)
                for (jj = 0; jj < L; jj++)
                    A[i][j][ii][jj] = NL + i + j + ii + jj;

    A[ni + 1][nj - 1][nii + 1][njj - 1] = N + M + K + L + NL + 7;

    } /*end region*/

    #pragma dvm get_actual(A)

    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj]) reduction(min(nloopi), min(nloopj), min(nloopii), min(nloopjj))
    for (i = 1; i < N - 1; i++)
        for (j = 1; j < M - 1; j++)
            for (ii = 1; ii < K - 1; ii++)
                for (jj = 1; jj < L - 1; jj++)
                    if (A[i][j][ii][jj] != C[i][j][ii][jj]) {
                        if (nloopi > i) nloopi = i;
                        if (nloopj > j) nloopj = j;
                        if (nloopii > ii) nloopii = ii;
                        if (nloopjj > jj) nloopjj = jj;
                    }
    if (nloopi == NL && nloopj == NL && nloopii == NL && nloopjj == NL)
        ansyes(tname);
    else
        ansno(tname);
}
/* ---------------------------------------------OWNCAL4108  */
void owncal4108()
{
    int C[N][M][K][L];
    char tname[] = "OWN4108";
    int i, j, ii, jj, NN, NM, NK, NLL, NNL;
    int nloopi, nloopj, nloopii, nloopjj;

    #pragma dvm array distribute[block][block][block][block]
    int A[N][M][K][L];

    NN = N;
    NM = M;
    NK = K;
    NLL = L;
    NNL = NL;

    serial4(C, NN, NM, NK, NLL, NNL);

    C[0][M - 1][0][L - 1] = N + M + K + L + NL + 8;
    nloopi = NL;
    nloopj = NL;
    nloopii = NL;
    nloopjj = NL;

    #pragma dvm region out(A)
    {
    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            for (ii = 0; ii < K; ii++)
                for (jj = 0; jj < L; jj++)
                    A[i][j][ii][jj] = NL + i + j + ii + jj;

    A[0][M - 1][0][L - 1] = N + M + K + L + NL + 8;

    } /*end region*/

    #pragma dvm get_actual(A)

    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj]) reduction(min(nloopi), min(nloopj), min(nloopii), min(nloopjj))
    for (i = 1; i < N - 1; i++)
        for (j = 1; j < M - 1; j++)
            for (ii = 1; ii < K - 1; ii++)
                for (jj = 1; jj < L - 1; jj++)
                    if (A[i][j][ii][jj] != C[i][j][ii][jj]) {
                        if (nloopi > i) nloopi = i;
                        if (nloopj > j) nloopj = j;
                        if (nloopii > ii) nloopii = ii;
                        if (nloopjj > jj) nloopjj = jj;
                    }
    if (nloopi == NL && nloopj == NL && nloopii == NL && nloopjj == NL)
        ansyes(tname);
    else
        ansno(tname);
}
/* ---------------------------------------------OWNCAL4109  */
void owncal4109()
{
    int C[N][M][K][L];
    char tname[] = "OWN4109";
    int i, j, ii, jj, NN, NM, NK, NLL, NNL;
    int nloopi, nloopj, nloopii, nloopjj;

    #pragma dvm array distribute[block][block][block][block]
    int A[N][M][K][L];

    NN = N;
    NM = M;
    NK = K;
    NLL = L;
    NNL = NL;

    serial4(C, NN, NM, NK, NLL, NNL);

    C[N - 1][0][K - 1][0] = N + M + K + L + NL + 9;
    nloopi = NL;
    nloopj = NL;
    nloopii = NL;
    nloopjj = NL;

    #pragma dvm region out(A)
    {
    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            for (ii = 0; ii < K; ii++)
                for (jj = 0; jj < L; jj++)
                    A[i][j][ii][jj] = NL + i + j + ii + jj;

    A[N][0][K - 1][0] = N + M + K + L + NL + 9;

    } /*end region*/

      #pragma dvm get_actual(A)

    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj]) reduction(min(nloopi), min(nloopj), min(nloopii), min(nloopjj))
    for (i = 1; i < N - 1; i++)
        for (j = 1; j < M - 1; j++)
            for (ii = 1; ii < K - 1; ii++)
                for (jj = 1; jj < L - 1; jj++)
                    if (A[i][j][ii][jj] != C[i][j][ii][jj]) {
                        if (nloopi > i) nloopi = i;
                        if (nloopj > j) nloopj = j;
                        if (nloopii > ii) nloopii = ii;
                        if (nloopjj > jj) nloopjj = jj;
                    }
    if (nloopi == NL && nloopj == NL && nloopii == NL && nloopjj == NL)
        ansyes(tname);
    else
        ansno(tname);
}
/* ---------------------------------------------OWNCAL4110  */
void owncal4110()
{
    int C[N][M][K][L];
    char tname[] = "OWN4110";
    int i, j, ii, jj, NN, NM, NK, NLL, NNL;
    int nloopi, nloopj, nloopii, nloopjj;

    #pragma dvm array distribute[block][block][block][block]
    int A[N][M][K][L];

    NN = N;
    NM = M;
    NK = K;
    NLL = L;
    NNL = NL;

    serial4(C, NN, NM, NK, NLL, NNL);

    C[0][0][K - 1][L - 1] = N + M + K + L + NL + 10;
    nloopi = NL;
    nloopj = NL;
    nloopii = NL;
    nloopjj = NL;

    #pragma dvm region out(A)
    {
    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj])
    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            for (ii = 0; ii < K; ii++)
                for (jj = 0; jj < L; jj++)
                    A[i][j][ii][jj] = NL + i + j + ii + jj;

    A[0][0][K - 1][L - 1] = N + M + K + L + NL + 10;

    } /*end region*/

    #pragma dvm get_actual(A)

    #pragma dvm parallel([i][j][ii][jj] on A[i][j][ii][jj]) reduction(min(nloopi), min(nloopj), min(nloopii), min(nloopjj))
    for (i = 1; i < N - 1; i++)
        for (j = 1; j < M - 1; j++)
            for (ii = 1; ii < K - 1; ii++)
                for (jj = 1; jj < L - 1; jj++)
                    if (A[i][j][ii][jj] != C[i][j][ii][jj]) {
                        if (nloopi > i) nloopi = i;
                        if (nloopj > j) nloopj = j;
                        if (nloopii > ii) nloopii = ii;
                        if (nloopjj > jj) nloopjj = jj;
                    }
    if (nloopi == NL && nloopj == NL && nloopii == NL && nloopjj == NL)
        ansyes(tname);
    else
        ansno(tname);
}

void serial4(int AR[][M][K][L], int NN, int NM, int NK, int NLL, int NNL)
{
    int i, j, ii, jj;
    for (i = 0; i < NN; i++)
        for (j = 0; j < NM; j++)
            for (ii = 0; ii < NK; ii++)
                for (jj = 0; jj < NLL; jj++)
                    AR[i][j][ii][jj] = NNL + i + j + ii + jj;
}

void ansyes(const char name[])
{
    printf("%s  -  complete\n", name);
}

void ansno(const char name[])
{
    printf("%s  -  ***error\n", name);
}
