/*    ALIGN32
TESTING align CLAUSE*/

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

static void align321();
static void align322();
static void align323();
static void align324();
static void align325();
static void align326();
static void align327();

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

static int NL = 10000;
static int ER = 100000;
static int s, cs, erri, i, j, n, m, k, l, ia, ja, na, ma, ib, jb, nb, mb, Avalue, Bvalue;

int main(int an, char **as)
{
    printf("=== START OF ALIGN32 ======================\n");
/*  ALIGN arrB[i][j] WITH arrA[i][j][1] matrix on section*/
    align321();
/*  ALIGN arrB[i][j] WITH arrA[j][i][5] matrix on section with rotation*/
    align322();
/*  ALIGN arrB[i][j] WITH arrA[j][1][2*i] matrix on section with
                                          rotation and stretching*/
    align323();
/*  ALIGN arrB[i][j] WITH arrA[][i][j] matrix replication*/
    align324();
/*  ALIGN arrB[i][j] WITH arrA[i+4][][j] matrix replication with shift*/
    align325();
/*  ALIGN arrB[i][j] WITH  arrA[-i+8][j][] matrix replication with reverse*/
//    align326();
/*  ALIGN arrB[][] WITH arrA[][][]*/
    align327();
    printf("=== END OF ALIGN32 ========================\n");
    return 0;
}
/* ---------------------------------------------ALIGN321*/
/* ALIGN arrB[i][j] WITH arrA[i][j][1] matrix on section*/
void align321()
{
/*     parameters for ALIGN arrB[i][j]
                      WITH arrA[k1i*i+li][k2j*j+lj][ln]*/
    #define AN1 5
    #define AN2 5
    #define AN3 5
    #define BN1 4
    #define BN2 4
    int k1i = 1, k2i = 0, k3i = 0, li = 0;
    int k1j = 0, k2j = 1, k3j = 0, lj = 0;
    int k1n = 0, k2n = 0, k3n = 0, ln = 1;

    #pragma dvm array distribute[block][block][block]
    int A3[AN1][AN2][AN3];
    #pragma dvm array align([i][j] with A3[k1i*i+li][k2j*j+lj][ln])
    int B2[BN1][BN2];
    char tname[] = "align321";

    erri = ER;
    s = 0;

    #pragma dvm actual(erri, s)
    #pragma dvm region local(A3, B2)
    {
    #pragma dvm parallel([i][j] on B2[i][j])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            B2[i][j] = 0;
    #pragma dvm parallel([i][j][n] on A3[i][j][n]) private(ib, jb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
            for (n = 0; n < AN3; n++)
            {
                A3[i][j][n] = i * NL / 10 + j * NL / 100 + n;
                if ((n == ln ) &&
                    ((i - li) == (((i - li) / k1i) * k1i)) &&
                    ((j - lj) == (((j - lj) / k2j) * k2j)) &&
                    (((i - li) / k1i) >= 0) &&
                    (((j - lj) / k2j) >= 0) &&
                    (((i - li) / k1i) < BN1) &&
                    (((j - lj) / k2j) < BN2))
                {
                    ib = (i - li) / k1i;
                    jb = (j - lj) / k2j;
                    B2[ib][jb] = ib * NL / 10 + jb * NL / 100;
                }
            }

    #pragma dvm parallel([i][j] on B2[i][j]) reduction(min(erri), sum(s)), private(ia, ja, na)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
        {
            int val = i * NL / 10 + j * NL / 100;
            s = s + B2[i][j];
            if (B2[i][j] != val)
                if (erri > val) erri = val;
            ia = k1i * i + li;
            ja = k2j * j + lj;
            na = ln;
            if (A3[ia][ja][na] != ia * NL / 10 + ja * NL / 100 + na)
                if (erri > val) erri = val;
        }

    }
    #pragma dvm get_actual(erri, s)

    cs = 0;
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            cs = cs + i * NL / 10 + j * NL / 100;
    if ((erri == ER) && (s == cs))
        ansyes(tname);
    else
        ansno(tname);
    #undef AN1
    #undef AN2
    #undef AN3
    #undef BN1
    #undef BN2
}
/* ---------------------------------------------ALIGN322*/
/* ALIGN arrB[i][j] WITH arrA[j][i][5] matrix on section with rotation*/
void align322()
{
/*     parameters for ALIGN arrB[i][j]
                      WITH arrA[k2i*j+li][k1j*i+lj][ln]*/
    #define AN1 5
    #define AN2 5
    #define AN3 6
    #define BN1 4
    #define BN2 4
    int k1i = 0, k2i = 1, k3i = 0, li = 0;
    int k1j = 1, k2j = 0, k3j = 0, lj = 0;
    int k1n = 0, k2n = 0, k3n = 0, ln = 5;

    #pragma dvm array distribute[block][block][block]
    int A3[AN1][AN2][AN3];
    #pragma dvm array align([i][j] with A3[k2i*j+li][k1j*i+lj][ln])
    int B2[BN1][BN2];
    char tname[] = "align322";

    erri = ER;
    s = 0;

    #pragma dvm actual(erri, s)
    #pragma dvm region local(A3, B2)
    {
    #pragma dvm parallel([i][j] on B2[i][j])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            B2[i][j] = 0;
    #pragma dvm parallel([i][j][n] on A3[i][j][n]) private(ib, jb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
            for (n = 0; n < AN3; n++)
            {
                A3[i][j][n] = i * NL / 10 + j * NL / 100 + n;
                if ((n == ln ) &&
                    ((i - li) == (((i - li) / k2i) * k2i)) &&
                    ((j - lj) == (((j - lj) / k1j) * k1j)) &&
                    (((i - li) / k2i) >= 0) &&
                    (((j - lj) / k1j) >= 0) &&
                    (((i - li) / k2i) < BN2) &&
                    (((j - lj) / k1j) < BN1))
                {
                    ib = (j - lj) / k1j;
                    jb = (i - li) / k2i;
                    B2[ib][jb] = ib * NL / 10 + jb * NL / 100;
                }
            }

    #pragma dvm parallel([i][j] on B2[i][j]) reduction(min(erri), sum(s)), private(ia, ja, na)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
        {
            int val = i * NL / 10 + j * NL / 100;
            s = s + B2[i][j];
            if (B2[i][j] != val)
                if (erri > val) erri = val;
            ia = k2i * j + li;
            ja = k1j * i + lj;
            na = ln;
            if (A3[ia][ja][na] != ia * NL / 10 + ja * NL / 100 + na)
                if (erri > val) erri = val;
        }

    }
    #pragma dvm get_actual(erri, s)

    cs = 0;
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            cs = cs + i * NL / 10 + j * NL / 100;
    if ((erri == ER) && (s == cs))
        ansyes(tname);
    else
        ansno(tname);
    #undef AN1
    #undef AN2
    #undef AN3
    #undef BN1
    #undef BN2
}
/* ---------------------------------------------ALIGN323*/
/* ALIGN arrB[i][j] WITH arrA[j][1][2*i] matrix on section with
                                         rotation and stretching*/
void align323()
{
/*     parameters for ALIGN arrB[i][j]
                      WITH arrA[k2i*j+li][lj][k1n*i+ln]*/
    #define AN1 5
    #define AN2 2
    #define AN3 7
    #define BN1 4
    #define BN2 4
    int k1i = 0, k2i = 1, k3i = 0, li = 0;
    int k1j = 0, k2j = 0, k3j = 0, lj = 1;
    int k1n = 2, k2n = 0, k3n = 0, ln = 0;

    #pragma dvm array distribute[block][block][block]
    int A3[AN1][AN2][AN3];
    #pragma dvm array align([i][j] with A3[k2i*j+li][lj][k1n*i+ln])
    int B2[BN1][BN2];
    char tname[] = "align323";

    erri = ER;
    s = 0;

    #pragma dvm actual(erri, s)
    #pragma dvm region local(A3, B2)
    {
    #pragma dvm parallel([i][j] on B2[i][j])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            B2[i][j] = 0;
    #pragma dvm parallel([i][j][n] on A3[i][j][n]) private(ib, jb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
            for (n = 0; n < AN3; n++)
            {
                A3[i][j][n] = i * NL / 10 + j * NL / 100 + n;
                if ((j == lj) &&
                    ((i - li) == (((i - li) / k2i) * k2i)) &&
                    ((n - ln) == (((n - ln) / k1n) * k1n)) &&
                    (((i - li) / k2i) >= 0) &&
                    (((n - ln) / k1n) >= 0) &&
                    (((i - li) / k2i) < BN2) &&
                    (((n - ln) / k1n) < BN1))
                {
                    ib = (n - ln) / k1n;
                    jb = (i - li) / k2i;
                    B2[ib][jb] = ib * NL / 10 + jb * NL / 100;
                }
            }

    #pragma dvm parallel([i][j] on B2[i][j]) reduction(min(erri), sum(s)), private(ia, ja, na)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
        {
            int val = i * NL / 10 + j * NL / 100;
            s = s + B2[i][j];
            if (B2[i][j] != val)
                if (erri > val) erri = val;
            ia = k2i * j + li;
            ja = lj;
            na = k1n * i + ln;
            if (A3[ia][ja][na] != ia * NL / 10 + ja * NL / 100 + na)
                if (erri > val) erri = val;
        }

    }
    #pragma dvm get_actual(erri, s)

    cs = 0;
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            cs = cs + i * NL / 10 + j * NL / 100;
    if ((erri == ER) && (s == cs))
        ansyes(tname);
    else
        ansno(tname);
    #undef AN1
    #undef AN2
    #undef AN3
    #undef BN1
    #undef BN2
}
/* ---------------------------------------------ALIGN324*/
/* ALIGN arrB[i][j] WITH arrA[][i][j] matrix replication*/
void align324()
{
/*     parameters for ALIGN arrB[i][j]
                      WITH arrA[][k1j*i+lj][k2n*j+ln]*/
    #define AN1 4
    #define AN2 6
    #define AN3 6
    #define BN1 4
    #define BN2 4
    int k1i = 0, k2i = 0, k3i = 0, li = 0;
    int k1j = 1, k2j = 0, k3j = 0, lj = 0;
    int k1n = 0, k2n = 1, k3n = 0, ln = 0;

    #pragma dvm array distribute[block][block][block]
    int A3[AN1][AN2][AN3];
    #pragma dvm array align([i][j] with A3[][k1j*i+lj][k2n*j+ln])
    int B2[BN1][BN2];
    char tname[] = "align324";

    erri = ER;
    s = 0;

    #pragma dvm actual(erri, s)
    #pragma dvm region local(A3, B2)
    {
    #pragma dvm parallel([i][j] on B2[i][j])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            B2[i][j] = i * NL / 10 + j * NL / 100;
    #pragma dvm parallel([i][j][n] on A3[i][j][n]) reduction(min(erri)), private(ib, jb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
            for (n = 0; n < AN3; n++)
            {
                A3[i][j][n] = i * NL / 10 + j * NL / 100 + n;
                if (((n - ln) == (((n - ln) / k2n) * k2n)) &&
                    ((j - lj) == (((j - lj) / k1j) * k1j)) &&
                    (((n - ln) / k2n) >= 0) &&
                    (((j - lj) / k1j) >= 0) &&
                    (((n - ln) / k2n) < BN2) &&
                    (((j - lj) / k1j) < BN1))
                {
                    int val = i * NL / 10 + j * NL / 100;
                    ib = (j - lj) / k1j;
                    jb = (n - ln) / k2n;
                    if (B2[ib][jb] != ib * NL / 10 + jb * NL / 100)
                        if (erri > val) erri = val;
                }
            }

    #pragma dvm parallel([i][j] on B2[i][j]) reduction(min(erri), sum(s)), private(ia, ja, na)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
        {
            int val = i * NL / 10 + j * NL / 100;
            s = s + B2[i][j];
            if (B2[i][j] != val)
                if (erri > val) erri = val;
        }

    }
    #pragma dvm get_actual(erri, s)

    cs = 0;
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            cs = cs + i * NL / 10 + j * NL / 100;
    if ((erri == ER) && (s == cs))
        ansyes(tname);
    else
        ansno(tname);
    #undef AN1
    #undef AN2
    #undef AN3
    #undef BN1
    #undef BN2
}
/* ---------------------------------------------ALIGN325*/
/*	ALIGN arrB[i][j] WITH arrA[i+4][][j] matrix replication with shift*/
void align325()
{
/*     parameters for ALIGN arrB[i][j]
                      WITH arrA[k1i*i+li][][k2n * j + ln]*/
    #define AN1 12
    #define AN2 6
    #define AN3 6
    #define BN1 4
    #define BN2 4
    int k1i = 1, k2i = 0, k3i = 0, li  = 4;
    int k1j = 1, k2j = 0, k3j = 0, lj  = 0;
    int k1n = 0, k2n = 1, k3n = 0, ln  = 0;

    #pragma dvm array distribute[block][block][block]
    int A3[AN1][AN2][AN3];
    #pragma dvm array align([i][j] with A3[k1i*i+li][][k2n*j+ln])
    int B2[BN1][BN2];
    char tname[] = "align325";

    erri = ER;
    s = 0;

    #pragma dvm actual(erri, s)
    #pragma dvm region local(A3, B2)
    {
    #pragma dvm parallel([i][j] on B2[i][j])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            B2[i][j] = i * NL / 10 + j * NL / 100;
    #pragma dvm parallel([i][j][n] on A3[i][j][n]) reduction(min(erri)), private(ib, jb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
            for (n = 0; n < AN3; n++)
            {
                A3[i][j][n] = i*NL/10 + j*NL/100 + n;
                if (((i - li) == (((i - li) / k1i) * k1i)) &&
                    ((n - ln) == (((n - ln) / k2n) * k2n)) &&
                    (((i - li) / k1i) >= 0) &&
                    (((n - ln) / k2n) >= 0) &&
                    (((i - li) / k1i) < BN1) &&
                    (((n - ln) / k2n) < BN2))
                {
                    int val = i * NL / 10 + j * NL / 100;
                    ib = (i - li) / k1i;
                    jb = (n - ln) / k2n;
                    if (B2[ib][jb] != ib * NL / 10 + jb * NL / 100)
                        if (erri > val) erri = val;
                }
            }

    #pragma dvm parallel([i][j] on B2[i][j]) reduction(min(erri), sum(s)), private(ia, ja, na)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
        {
            int val = i * NL / 10 + j * NL / 100;
            s = s + B2[i][j];
            if (B2[i][j] != val)
                if (erri > val) erri = val;
        }

    }
    #pragma dvm get_actual(erri, s)

    cs = 0;
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            cs = cs + i * NL / 10 + j * NL / 100;
    if ((erri == ER) && (s == cs))
        ansyes(tname);
    else
        ansno(tname);
    #undef AN1
    #undef AN2
    #undef AN3
    #undef BN1
    #undef BN2
}
/* ---------------------------------------------ALIGN326*/
/*	ALIGN arrB[i][j] WITH arrA[-i+8][j][] matrix replication with reverse*/
void align326()
{
/*     parameters for ALIGN arrB[i][j]
                      WITH arrA[k1i*i+li][k2j*j+lj][]*/
    #define AN1 9
    #define AN2 5
    #define AN3 5
    #define BN1 7
    #define BN2 4
    int k1i = -1, k2i = 0, k3i = 0, li = 8;
    int k1j = 0, k2j = 1, k3j = 0, lj = 0;
    int k1n = 0, k2n = 0, k3n = 0, ln = 0;

    #pragma dvm array distribute[block][block][block]
    int A3[AN1][AN2][AN3];
    #pragma dvm array align([i][j] with A3[k1i*i+li][k2j*j+lj][])
    int B2[BN1][BN2];
    char tname[] = "align326";

    erri = ER;
    s = 0;

    #pragma dvm actual(erri, s)
    #pragma dvm region local(A3, B2)
    {
    #pragma dvm parallel([i][j] on B2[i][j])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            B2[i][j] = i * NL / 10 + j * NL / 100;
    #pragma dvm parallel([i][j][n] on A3[i][j][n]) reduction(min(erri)), private(ib, jb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
            for (n = 0; n < AN3; n++)
            {
                A3[i][j][n] = i * NL / 10 + j * NL / 100 + n;
                if (((i - li) == (((i - li) / k1i) * k1i)) &&
                    ((j - lj) == (((j  -lj) / k2j) * k2j)) &&
                    (((i - li) / k1i) >= 0) &&
                    (((j - lj) / k2j) >= 0) &&
                    (((i - li) / k1i) < BN1) &&
                    (((j - lj) / k2n) < BN2))
                {
                    int val = i * NL / 10 + j * NL / 100;
                    ib = (i - li) / k1i;
                    jb = (j - lj) / k2j;
                    if (B2[ib][jb] != ib * NL / 10 + jb * NL / 100)
                        if (erri > val) erri = val;
                }
            }

    #pragma dvm parallel([i][j] on B2[i][j]) reduction(min(erri), sum(s)), private(ia, ja, na)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
        {
            int val = i * NL / 10 + j * NL / 100;
            s = s + B2[i][j];
            if (B2[i][j] != val)
                if (erri > val) erri = val;
        }

    }
    #pragma dvm get_actual(erri, s)

    cs = 0;
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            cs = cs + i * NL / 10 + j * NL / 100;
    if ((erri == ER) && (s == cs))
        ansyes(tname);
    else
        ansno(tname);
    #undef AN1
    #undef AN2
    #undef AN3
    #undef BN1
    #undef BN2
}
/* ---------------------------------------------ALIGN327*/
/*  ALIGN arrB[][] WITH arrA[][][]*/
void align327()
{
/*     parameters for ALIGN arrB[][]
                      WITH arrA[][][]*/
    #define AN1 7
    #define AN2 5
    #define AN3 5
    #define BN1 7
    #define BN2 4
    int k1i = 0, k2i = 0, k3i = 0, li = 0;
    int k1j = 0, k2j = 0, k3j = 0, lj = 0;
    int k1n = 0, k2n = 0, k3n = 0, ln = 1;

    #pragma dvm array distribute[block][block][block]
    int A3[AN1][AN2][AN3];
    #pragma dvm array align([][] with A3[][][])
    int B2[BN1][BN2];
    char tname[] = "align327";

    erri = ER;
    s = 0;

    #pragma dvm actual(erri, s)
    #pragma dvm region local(A3, B2)
    {
    #pragma dvm parallel([i][j] on B2[i][j])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            B2[i][j] = i * NL / 10 + j * NL / 100;
    #pragma dvm parallel([i][j][n] on A3[i][j][n]) reduction(min(erri)), private(ib, jb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
            for (n = 0; n < AN3; n++)
            {
                A3[i][j][n] = i * NL / 10 + j * NL / 100 + n;
                for (ib = 0; ib < BN1; ib++)
                    for (jb = 0; jb < BN2; jb++)
                    {
                        int val = i * NL / 10 + j * NL / 100;
                        if (B2[ib][jb] != ib * NL / 10 + jb * NL / 100)
                            if (erri > val) erri = val;
                    }
            }

    }
    #pragma dvm get_actual(erri, s)

    cs = 0;
    if ((erri == ER) && (s == cs))
        ansyes(tname);
    else
        ansno(tname);
    #undef AN1
    #undef AN2
    #undef AN3
    #undef BN1
    #undef BN2
}

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

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