/*  ACR11

    TESTING OF THE ACROSS CLAUSE'.
    DISTRIBUTED ARRAY A(N) IS TO HAVE DIFFERENT
    FLOW-DEP-LENGTH ON BOTH SIDES */

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

#define Min(a, b) (((a) < (b)) ? (a) : (b))

static void acr1101();
static void acr1102();
static void acr1103();
static void acr1104();
static void acr1105();
static void acr1106();
static void acr1107();
static void acr1108();
static void acr1109();
static void acr1110();

static void ansyes(const char tname[]);
static void ansno(const char tname[]);

static int i;

int main(int an, char **as)
{
    printf("===START OF ACR11========================\n");
    /* ---------------------------------------- */
    acr1101();
    /* ---------------------------------------- */
    acr1102();
    /* ---------------------------------------- */
    acr1103();
    /* ---------------------------------------- */
    acr1104();
    /* ---------------------------------------- */
    acr1105();
    /* ---------------------------------------- */
    acr1106();
    /* ---------------------------------------- */
    acr1107();
    /* ---------------------------------------- */
    acr1108();
    /* ---------------------------------------- */
    acr1109();
    /* ---------------------------------------- */
    acr1110();
    /* ---------------------------------------- */

    printf("=== END OF ACR11 =========================\n");
    return 0;
}
/* ---------------------------------------------ACR1101*/
void acr1101()
{
    #define N 8
    #define NL 1000
    char tname[] = "ACR1101 ";
    int nloop;
    #pragma dvm array distribute[block]
    int *A;
    A = (int (*))malloc(N * sizeof(int));
    int *C;
    C = (int (*))malloc(N * sizeof(int));
    int NNL = NL;

    for (i = 0; i < N; i++)
        C[i] = NNL + i;
    nloop = NL;

    for (i = 1; i < N - 1; i++)
        C[i] = C[i - 1] + C[i + 1];

    #pragma dvm actual(nloop)
    #pragma dvm region
    {
    #pragma dvm parallel([i] on A[i])
    for (i = 0; i < N; i++)
        A[i] = NL + i;

    #pragma dvm parallel([i] on A[i]) across(A[1:1])
    for (i = 1; i < N - 1; i++)
        A[i] = A[i - 1] + A[i + 1];
    }
    #pragma dvm get_actual(A)
    #pragma dvm parallel([i] on A[i]) reduction(min(nloop))
    for (i = 1; i < N - 1; i++)
        if (A[i] != C[i])
            nloop = Min(nloop, i);
    #pragma dvm get_actual(nloop)
    if (nloop == NL)
        ansyes(tname);
    else
        ansno(tname);

    free(C);
    free(A);
    #undef N
    #undef NL
}
/* ---------------------------------------------ACR1102 */
void acr1102()
{
    #define N 16
    #define NL 1000
    char tname[] = "ACR1102 ";
    int nloop;
    #pragma dvm array distribute[block]
    int *A;
    A = (int (*))malloc(N * sizeof(int));
    int *C;
    C = (int (*))malloc(N * sizeof(int));
    int NNL = NL;

    for (i = 0; i < N; i++)
        C[i] = NNL + i;
    nloop = NL;

    for (i = 1; i < N - 1; i++)
        C[i] = C[i] + C[i + 1];

    #pragma dvm actual(nloop)
    #pragma dvm region
    {
    #pragma dvm parallel([i] on A[i])
    for (i = 0; i < N; i++)
        A[i] = NL + i;

    #pragma dvm parallel([i] on A[i]) across(A[0:1])
    for (i = 1; i < N - 1; i++)
        A[i] = A[i] + A[i + 1];
    }
    #pragma dvm get_actual(A)
    #pragma dvm parallel([i] on A[i]) reduction(min(nloop))
    for (i = 1; i < N - 1; i++)
        if (A[i] != C[i])
            nloop = Min(nloop, i);
    #pragma dvm get_actual(nloop)
    if (nloop == NL)
        ansyes(tname);
    else
        ansno(tname);

    free(C);
    free(A);
    #undef N
    #undef NL
}
/* ---------------------------------------------ACR1103 */
void acr1103()
{
    #define N 16
    #define NL 1000
    char tname[] = "ACR1103 ";
    int nloop;
    #pragma dvm array distribute[block]
    int *A;
    A = (int (*))malloc(N * sizeof(int));
    int *C;
    C = (int (*))malloc(N * sizeof(int));
    int NNL = NL;

    for (i = 0; i < N; i++)
        C[i] = NNL + i;
    nloop = NL;

    for (i = 1; i < N - 1; i++)
        C[i] = C[i - 1] + C[i];
    #pragma dvm actual(nloop)
    #pragma dvm region
    {
    #pragma dvm parallel([i] on A[i])
    for (i = 0; i < N; i++)
        A[i] = NL + i;

    #pragma dvm parallel([i] on A[i]) across(A[1:0])
    for (i = 1; i < N - 1; i++)
        A[i] = A[i - 1] + A[i];
    }
    #pragma dvm get_actual(A)
    #pragma dvm parallel([i] on A[i]) reduction(min(nloop))
    for (i = 1; i < N - 1; i++)
        if (A[i] != C[i])
            nloop = Min(nloop, i);
    #pragma dvm get_actual(nloop)
    if (nloop == NL)
        ansyes(tname);
    else
        ansno(tname);

    free(C);
    free(A);
    #undef N
    #undef NL
}
/* ---------------------------------------------ACR1104 */
void acr1104()
{
    #define N 16
    #define NL 1000
    char tname[] = "ACR1104 ";
    int nloop;
    #pragma dvm array distribute[block], shadow[2:2]
    int *A;
    A = (int (*))malloc(N * sizeof(int));
    int *C;
    C = (int (*))malloc(N * sizeof(int));
    int NNL = NL;

    for (i = 0; i < N; i++)
        C[i] = NNL + i;
    nloop = NL;

    for (i = 2; i < N - 2; i++)
        C[i] = C[i - 1] + C[i + 1] + C[i + 2] + C[i - 2];
    #pragma dvm actual(nloop)
    #pragma dvm region
    {
    #pragma dvm parallel([i] on A[i])
    for (i = 0; i < N; i++)
        A[i] = NL + i;

    #pragma dvm parallel([i] on A[i]) across(A[2:2])
    for (i = 2; i < N - 2; i++)
        A[i] = A[i - 1] + A[i + 1] + A[i + 2] + A[i - 2];
    }
    #pragma dvm get_actual(A)
    #pragma dvm parallel([i] on A[i]) reduction(min(nloop))
    for (i = 2; i < N - 2; i++)
        if (A[i] != C[i])
            nloop = Min(nloop, i);
    #pragma dvm get_actual(nloop)
    if (nloop == NL)
        ansyes(tname);
    else
        ansno(tname);

    free(C);
    free(A);
    #undef N
    #undef NL
}
/* ---------------------------------------------ACR1105 */
void acr1105()
{
    #define N 16
    #define NL 1000
    char tname[] = "ACR1105 ";
    int nloop;
    #pragma dvm array distribute[block], shadow[2:2]
    int *A;
    A = (int (*))malloc(N * sizeof(int));
    int *C;
    C = (int (*))malloc(N * sizeof(int));
    int NNL = NL;

    for (i = 0; i < N; i++)
        C[i] = NNL + i;
    nloop = NL;

    for (i = 1; i < N - 2; i++)
        C[i] = C[i + 1] + C[i + 2];
    #pragma dvm actual(nloop)
    #pragma dvm region
    {
    #pragma dvm parallel([i] on A[i])
    for (i = 0; i < N; i++)
        A[i] = NL + i;

    #pragma dvm parallel([i] on A[i]) across(A[0:2])
    for (i = 1; i < N - 2; i++)
        A[i] = A[i + 1] + A[i + 2];
    }
    #pragma dvm get_actual(A)
    #pragma dvm parallel([i] on A[i]) reduction(min(nloop))
    for (i = 1; i < N - 2; i++)
        if (A[i] != C[i])
            nloop = Min(nloop, i);
    #pragma dvm get_actual(nloop)
    if (nloop == NL)
        ansyes(tname);
    else
        ansno(tname);

    free(C);
    free(A);
    #undef N
    #undef NL
}
/* ---------------------------------------------ACR1106 */
void acr1106()
{
    #define N 16
    #define NL 1000
    char tname[] = "ACR1106 ";
    int nloop;
    #pragma dvm array distribute[block], shadow[2:2]
    int *A;
    A = (int (*))malloc(N * sizeof(int));
    int *C;
    C = (int (*))malloc(N * sizeof(int));
    int NNL = NL;

    for (i = 0; i < N; i++)
        C[i] = NNL + i;
    nloop = NL;

    for (i = 2; i < N; i++)
        C[i] = C[i - 1] + C[i - 2];
    #pragma dvm actual(nloop)
    #pragma dvm region
    {
    #pragma dvm parallel([i] on A[i])
    for (i = 0; i < N; i++)
        A[i] = NL + i;

    #pragma dvm parallel([i] on A[i]) across(A[2:0])
    for (i = 2; i < N; i++)
        A[i] = A[i - 1] + A[i - 2];
    }
    #pragma dvm get_actual(A)
    #pragma dvm parallel([i] on A[i]) reduction(min(nloop))
    for (i = 2; i < N; i++)
        if (A[i] != C[i])
            nloop = Min(nloop, i);
    #pragma dvm get_actual(nloop)
    if (nloop == NL)
        ansyes(tname);
    else
        ansno(tname);

    free(C);
    free(A);
    #undef N
    #undef NL
}
/* ---------------------------------------------ACR1107 */
void acr1107()
{
    #define N 16
    #define NL 1000
    char tname[] = "ACR1107 ";
    int nloop;
    #pragma dvm array distribute[block], shadow[3:3]
    int *A;
    A = (int (*))malloc(N * sizeof(int));
    int *C;
    C = (int (*))malloc(N * sizeof(int));
    int NNL = NL;

    for (i = 0; i < N; i++)
        C[i] = NNL + i;
    nloop = NL;

    for (i = 3; i < N - 3; i++)
        C[i] = C[i - 1] + C[i + 1] + C[i + 2] + C[i - 2] + C[i - 3] + C[i + 3];
    #pragma dvm actual(nloop)
    #pragma dvm region
    {
    #pragma dvm parallel([i] on A[i])
    for (i = 0; i < N; i++)
        A[i] = NL + i;

    #pragma dvm parallel([i] on A[i]) across(A[3:3])
    for (i = 3; i < N - 3; i ++)
        A[i] = A[i - 1] + A[i + 1] + A[i + 2] + A[i - 2] + A[i - 3] + A[i + 3];
    }
    #pragma dvm get_actual(A)
    #pragma dvm parallel([i] on A[i]) reduction(min(nloop))
    for (i = 3; i < N - 3; i ++)
        if (A[i] != C[i])
            nloop = Min(nloop, i);
    #pragma dvm get_actual(nloop)
    if (nloop == NL)
        ansyes(tname);
    else
        ansno(tname);

    free(C);
    free(A);
    #undef N
    #undef NL
}
/* ---------------------------------------------ACR1108 */
void acr1108()
{
    #define N 24
    #define NL 1000
    char tname[] = "ACR1108 ";
    int nloop;
    #pragma dvm array distribute[block], shadow[3:3]
    int *A;
    A = (int (*))malloc(N * sizeof(int));
    int *C;
    C = (int (*))malloc(N * sizeof(int));
    int NNL = NL;

    for (i = 0; i < N; i++)
        C[i] = NNL + i;
    nloop = NL;

    for (i = 1; i < N - 3; i++)
        C[i] = C[i + 1] + C[i + 2] + C[i + 3];
    #pragma dvm actual(nloop)
    #pragma dvm region
    {
    #pragma dvm parallel([i] on A[i])
    for (i = 0; i < N; i++)
        A[i] = NL + i;

    #pragma dvm parallel([i] on A[i]) across(A[0:3])
    for (i = 1; i < N - 3; i ++)
        A[i] = A[i + 1] + A[i + 2] + A[i + 3];
    }
    #pragma dvm get_actual(A)
    #pragma dvm parallel([i] on A[i]) reduction(min(nloop))
    for (i = 1; i < N - 3; i ++)
        if (A[i] != C[i])
            nloop = Min(nloop, i);
    #pragma dvm get_actual(nloop)
    if (nloop == NL)
        ansyes(tname);
    else
        ansno(tname);

    free(C);
    free(A);
    #undef N
    #undef NL
}
/* ---------------------------------------------ACR1109 */
void acr1109()
{
    #define N 24
    #define NL 1000
    char tname[] = "ACR1109 ";
    int nloop;
    #pragma dvm array distribute[block], shadow[3:3]
    int *A;
    A = (int (*))malloc(N * sizeof(int));
    int *C;
    C = (int (*))malloc(N * sizeof(int));
    int NNL = NL;

    for (i = 0; i < N; i++)
        C[i] = NNL + i;
    nloop = NL;

    for (i = 3; i < N; i++)
        C[i] = C[i - 1] + C[i - 2] + C[i - 3];
    #pragma dvm actual(nloop)
    #pragma dvm region
    {
    #pragma dvm parallel([i] on A[i])
    for (i = 0; i < N; i++)
        A[i] = NL + i;

    #pragma dvm parallel([i] on A[i]) across(A[3:0])
    for (i = 3; i < N; i ++)
        A[i] = A[i - 1] + A[i - 2] + A[i - 3];
    }
    #pragma dvm get_actual(A)
    #pragma dvm parallel([i] on A[i]) reduction(min(nloop))
    for (i = 3; i < N; i ++)
        if (A[i] != C[i])
            nloop = Min(nloop, i);
    #pragma dvm get_actual(nloop)
    if (nloop == NL)
        ansyes(tname);
    else
        ansno(tname);

    free(C);
    free(A);
    #undef N
    #undef NL
}
/* ---------------------------------------------ACR1110 */
void acr1110()
{
    #define N 60
    #define NL 1000
    char tname[] = "ACR1110 ";
    int nloop;
    #pragma dvm array distribute[block], shadow[11:11]
    int *A;
    A = (int (*))malloc(N * sizeof(int));
    int *C;
    C = (int (*))malloc(N * sizeof(int));
    int NNL = NL;

    for (i = 0; i < N; i++)
        C[i] = NNL + i;
    nloop = NL;

    for (i = 11; i < N - 11; i++)
        C[i] = C[i - 9] + C[i + 9] + C[i + 10] + C[i - 10] + C[i - 11] + C[i + 11];
    #pragma dvm actual(nloop)
    #pragma dvm region
    {
    #pragma dvm parallel([i] on A[i])
    for (i = 0; i < N; i++)
        A[i] = NL + i;

    #pragma dvm parallel([i] on A[i]) across(A[11:11])
    for (i = 11; i < N - 11; i ++)
        A[i] = A[i - 9] + A[i + 9] + A[i + 10] + A[i - 10] + A[i - 11] + A[i + 11];
    }
    #pragma dvm get_actual(A)
    #pragma dvm parallel([i] on A[i]) reduction(min(nloop))
    for (i = 11; i < N - 11; i ++)
        if (A[i] != C[i])
            nloop = Min(nloop, i);
    #pragma dvm get_actual(nloop)
    if (nloop == NL)
        ansyes(tname);
    else
        ansno(tname);

    free(C);
    free(A);
    #undef N
    #undef NL
}
/* ----------------------------------------------- */
void ansyes(const char name[])
{
    printf("%s  -  complete\n", name);
}

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