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

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

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

static void owncal3101();
static void owncal3102();
static void owncal3103();
static void owncal3104();
static void owncal3105();
static void owncal3106();
static void owncal3107();
static void owncal3108();
static void owncal3109();
static void owncal3110();

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

int main(int argc, char *argv[])
{
    printf("===START OF OWNCAL31========================\n");
    owncal3101();
    owncal3102();
    owncal3103();
    owncal3104();
    owncal3105();
    owncal3106();
    owncal3107();
    owncal3108();
    owncal3109();
    owncal3110();

    printf("=== END OF OWNCAL31 ========================= \n");
    return 0;
}
/* ---------------------------------------------OWNCAL3101  */
void owncal3101()
{
    int C[N][M][K];
    char tname[] = "OWN3101";
    int i, j, ii, NN, NM, NK, NNL, nloopi, nloopj, nloopii;

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

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

    serial3(C, NN, NM, NK, NNL);

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

    #pragma dvm region out(A)
    {

    for (i = 0; i < N; i++)
        for (j = 0; j < M; j++)
            for (ii = 0; ii < K; ii++)
                A[i][j][ii] = NL + i + j + ii;

    } /*end region*/

    #pragma dvm get_actual(A)

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

/* ---------------------------------------------OWNCAL3102  */
void owncal3102()
{
    int C[N][M][K];
    char tname[] = "OWN3102";
    int i, j, ii, NN, NM, NK, NNL, nloopi, nloopj, nloopii;

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

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

    serial3(C, NN, NM, NK, NNL);
    C[0][0][0] = N + M + K + NL + 2;

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

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

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

    } /*end region*/

    #pragma dvm get_actual(A)

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

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

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

    serial3(C, NN, NM, NK, NNL);
    ni = N / 2;
    nj = M / 2;
    nii = K / 2;

    C[ni][nj][nii] = N + M + K + NL + 3;

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

    #pragma dvm actual(ni, nj, nii)

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

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

    } /*end region*/

    #pragma dvm get_actual(A)

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

/* ---------------------------------------------OWNCAL3104  */
void owncal3104()
{
    int C[N][M][K];
    char tname[] = "OWN3104";
    int i, j, ii, NN, NM, NK, NNL, nloopi, nloopj, nloopii;
    int ni, nj, nii;

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

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

    serial3(C, NN, NM, NK, NNL);
    ni = N / 2;
    nj = M / 2;
    nii = K / 2;

    C[ni + 1][nj + 1][nii + 1] = N + M + K + NL + 4;

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

    #pragma dvm actual(ni, nj, nii)

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

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

    } /*end region*/

    #pragma dvm get_actual(A)

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


/* ---------------------------------------------OWNCAL3105  */
void owncal3105()
{
    int C[N][M][K];
    char tname[] = "OWN3105";
    int i, j, ii, NN, NM, NK, NNL, nloopi, nloopj, nloopii;
    int ni, nj, nii;

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

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

    serial3(C, NN, NM, NK, NNL);
    ni = N / 2;
    nj = M / 2;
    nii = K / 2;

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

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

    #pragma dvm actual(ni, nj, nii)

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

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

    } /*end region*/

    #pragma dvm get_actual(A)

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

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

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

    serial3(C, NN, NM, NK, NNL);
    ni = N / 2;
    nj = M / 2;
    nii = K / 2;

    C[ni + 1][nj - 1][nii + 1] = N + M + K + NL + 6;

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

    #pragma dvm actual(ni, nj, nii)

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

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

    } /*end region*/

    #pragma dvm get_actual(A)

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


/* ---------------------------------------------OWNCAL3107  */
void owncal3107()
{
    int C[N][M][K];
    char tname[] = "OWN3107";
    int i, j, ii, NN, NM, NK, NNL, nloopi, nloopj, nloopii;
    int ni, nj, nii;

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

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

    serial3(C, NN, NM, NK, NNL);
    ni = N / 2;
    nj = M / 2;
    nii = K / 2;

    C[ni - 1][nj + 1][nii - 1] = N + M + K + NL + 7;

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

    #pragma dvm actual(ni, nj, nii)

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

    A[ni - 1][nj + 1][nii - 1] = N + M + K + NL + 7;
    } /*end region*/

    #pragma dvm get_actual(A)

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

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

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

    serial3(C, NN, NM, NK, NNL);

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

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


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

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

    } /*end region*/

    #pragma dvm get_actual(A)

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


/* ---------------------------------------------OWNCAL3109  */
void owncal3109()
{
    int C[N][M][K];
    char tname[] = "OWN3109";
    int i, j, ii, NN, NM, NK, NNL, nloopi, nloopj, nloopii;

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

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

    serial3(C, NN, NM, NK, NNL);

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

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


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

    A[N - 1][M - 1][0] = N + M + K + NL + 9;
    } /*end region*/

    #pragma dvm get_actual(A)

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

/* ---------------------------------------------OWNCAL3110  */
void owncal3110()
{
    int C[N][M][K];
    char tname[] = "OWN3110";
    int i, j, ii, NN, NM, NK, NNL, nloopi, nloopj, nloopii;
    int nj;

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

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

    serial3(C, NN, NM, NK, NNL);

    nj = M / 2;
    C[0][nj + 1][K - 1] = N + M + K + NL + 10;

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

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

    A[0][nj + 1][K - 1] = N + M + K + NL + 10;
    } /*end region*/

    #pragma dvm get_actual(A)

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


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

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

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