/*    REALIGN33
Testing ALIGN and REALIGN directives */

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

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

static void realign331();
static void realign332();
static void realign333();
static void realign334();
static void realign335();
static void realign336();

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

static int NL = 10000;
static int ER = 100000;

static int s,cs,erria,errib,i,j,n,l,ia,ja,na,ib,jb,nb;

int main(int an, char **as)
{
    printf("=== START OF REALIGN33 ===================\n");

    /* ALIGN arrB3[i][j][n] WITH arrA3[i][j][n]
       REALIGN arrB3[i][j][n] WITH arrA3[i+1][j+2][n+3] */
    realign331();
    /* ALIGN arrB3[i][j][n] WITH arrA3[i][j][n]
       REALIGN arrB3[i][j][n] WITH arrA3[2*i][3*j][5*n] */
    realign332();
    /* ALIGN arrB3[i][j][n] WITH arrA3[i+2][j+4][n+3]
       REALIGN arrB3[i][j][n] WITH arrA3[2*i+1][2*n][j+1] */
    realign333();
    /* ALIGN arrB3[i][j][n] WITH arrA3[n+1][3*i+1][j+2]
       REALIGN arrB3[i][j][n] WITH arrA3[2*j][i+1][2*n+1] */
    realign334();
    /* ALIGN arrB[*][*][*] WITH arrA[*][*][*]
       REALIGN arrB[i][j][n] WITH arrA[i][j][n] */
    realign335();
    /* ALIGN arrB[i][j][n] WITH arrA[i][j+1][2*n+1]
       REALIGN arrB[*][j][n] WITH arrA[j+1][n][1] */
    realign336();

    printf("=== END OF REALIGN33 ===================\n");
    return 0;
}

/* ----------------------------------------------------realign331 */
    /* ALIGN arrB3[i][j][n]   WITH arrA3[i][j][n]
       REALIGN arrB3[i][j][n] WITH arrA3[i+1][j+2][n+3] */

void realign331()
{
    #define AN1 10
    #define AN2 10
    #define AN3 10
    #define BN1 9
    #define BN2 8
    #define BN3 6

/* parameters for ALIGN arrB[i][j][n] WITH arrA[k1i*i+li][k2j*j+lj][k3n*n+ln] */
    int k1i=1, li=0;
    int k2j=1, lj=0;
    int k3n=1, ln=0;
/* parameters for REALIGN arrB[i][j][n] WITH arrA[kr1i*i+lri][kr2j*j+lrj][kr3n*n+lrn] */
    int kr1i=1, lri=1;
    int kr2j=1, lrj=2;
    int kr3n=1, lrn=3;

    #pragma dvm array distribute[block][block][block]
    int A3[AN1][AN2][AN3];
    #pragma dvm array align([i][j][n] with A3[k1i*i+li][k2j*j+lj][k3n*n+ln])
    int B3[BN1][BN2][BN3];

    char tname[] = "realign331";

    erria = ER;
    errib = ER;

    #pragma dvm region inout(A3,B3)
    {

//  A3 = 0;
    #pragma dvm parallel([i][j][n] on A3[i][j][n])
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
            for (n = 0; n < AN3; n++)
                A3[i][j][n] = 0;

//  B3 = 0;
    #pragma dvm parallel([i][j][n] on B3[i][j][n])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
                B3[i][j][n] = 0;

    #pragma dvm parallel([i][j][n] on A3[i][j][n]) private(ib,jb,nb)
    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*NL/1000;
                if (((i-li) == (((i-li)/k1i) * k1i))  &&
                    ((j-lj) == (((j-lj)/k2j) * k2j))  &&
                    ((n-ln) == (((n-ln)/k3n) * k3n))  &&
                    (((i-li)/k1i) >= 0)   &&
                    (((j-lj)/k2j) >= 0)   &&
                    (((n-ln)/k3n) >= 0)   &&
                    (((i-li)/k1i) < BN1)  &&
                    (((j-lj)/k2j) < BN2)  &&
                    (((n-ln)/k3n) < BN3))
                {
                    ib = (i-li)/k1i;
                    jb = (j-lj)/k2j;
                    nb = (n-ln)/k3n;
                    B3[ib][jb][nb]=ib*NL/10+jb*NL/100+nb*NL/1000;
                }
    } /* end of loop */

    } /* end region */

    #pragma dvm realign(B3[i][j][n] with A3[kr1i*i+lri][kr2j*j+lrj][kr3n*n+lrn])

    s=0;

    #pragma dvm actual (erria, errib, s)

    #pragma dvm region inlocal(A3,B3)
    {
    #pragma dvm parallel([i][j][n] on B3[i][j][n]) reduction(min(erria),min(errib),sum(s)),private(ia,ja,na)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
    {
                s = s + B3[i][j][n];
                if (B3[i][j][n] != (i*NL/10+j*NL/100+n*NL/1000))
                    errib = Min(errib,i*NL/10 + j*NL/100 + n*NL/1000);
                ia=kr1i * i + lri;
                ja=kr2j * j + lrj;
                na=kr3n * n + lrn;
                if (A3[ia][ja][na] != (ia*NL/10+ja*NL/100+na*NL/1000))
                    erria = Min(erria,ia*NL/10 + ja*NL/100 + na*NL/1000);
    } /* end of loop */

    } /* end region */

    cs = 0;
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
                cs = cs + i*NL/10 + j*NL/100 + n*NL/1000;

    #pragma dvm get_actual(erria, errib, s)

    if ((erria == ER) && (errib == ER) && (s == cs))
        ansyes(tname);
    else
        ansno(tname);

    #undef AN1
    #undef AN2
    #undef AN3
    #undef BN1
    #undef BN2
    #undef BN3
}

/*  ----------------------------------------------------realign332 */
    /* ALIGN arrB3[i][j][n] WITH arrA3[i][j][n]
       REALIGN arrB3[i][j][n] WITH arrA3[2*i][3*j][5*n] */

void realign332()
{
    #define AN1 12
    #define AN2 16
    #define AN3 25
    #define BN1 4
    #define BN2 3
    #define BN3 5

/* parameters for ALIGN arrB[i][j][n] WITH arrA[k1i*i+li][k2j*j+lj][k3n*n+ln] */
    int k1i=1, li=0;
    int k2j=1, lj=0;
    int k3n=1, ln=0;
/* parameters for REALIGN arrB[i][j][n] WITH arrA[kr1i*i+lri][kr2j*j+lrj][kr3n*n+lrn] */
    int kr1i=2, lri=0;
    int kr2j=3, lrj=0;
    int kr3n=5, lrn=0;

    #pragma dvm array distribute[block][block][block]
    int A3[AN1][AN2][AN3];
    #pragma dvm array align([i][j][n] with A3[k1i*i+li][k2j*j+lj][k3n*n+ln])
    int B3[BN1][BN2][BN3];

    char tname[] = "realign332";

    erria = ER;
    errib = ER;

    #pragma dvm region inout(A3,B3)
    {

    #pragma dvm parallel([i][j][n] on A3[i][j][n])
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
            for (n = 0; n < AN3; n++)
                A3[i][j][n] = 0;

    #pragma dvm parallel([i][j][n] on B3[i][j][n])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
                B3[i][j][n] = 0;

    #pragma dvm parallel([i][j][n] on A3[i][j][n]) private(ib,jb,nb)
    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*NL/1000 + 10;
                if (
                   ((i-li) == (((i-li)/k1i) * k1i)) &&
                   ((j-lj) == (((j-lj)/k2j) *k2j))  &&
                   ((n-ln) == (((n-ln)/k3n) * k3n)) &&
                   (((i-li)/k1i) >= 0)  &&
                   (((j-lj)/k2j) >= 0)  &&
                   (((n-ln)/k3n) >= 0)  &&
                   (((i-li)/k1i) < BN1)  &&
                   (((j-lj)/k2j) < BN2)  &&
                   (((n-ln)/k3n) < BN3)
                   )
                {
                    ib = (i-li)/k1i;
                    jb = (j-lj)/k2j;
                    nb = (n-ln)/k3n;
                    B3[i][j][n]=ib*NL/10+jb*NL/100+nb*NL/1000 + 5;
                }
    } /* end of loop */

    } /* end region */

    #pragma dvm realign(B3[i][j][n] with A3[kr1i*i+lri][kr2j*j+lrj][kr3n*n+lrn])

    s=0;

    #pragma dvm actual (erria, errib, s)

    #pragma dvm region inlocal(A3),inlocal(B3)
    {

    #pragma dvm parallel([i][j][n] on B3[i][j][n]) reduction(min(erria), min(errib), sum(s)), private(ia, ja, na)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++) {
               s = s + B3[i][j][n];
               if (B3[i][j][n] != (i*NL/10+j*NL/100+n*NL/1000) + 5)
                   errib = Min(errib,i*NL/10 + j*NL/100 + n*NL/1000);
               ia=kr1i * i + lri;
               ja=kr2j * j + lrj;
               na=kr3n * n + lrn;
               if (A3[ia][ja][na] != (ia*NL/10+ja*NL/100+na*NL/1000)+10)
                  erria = Min(erria,ia*NL/10 + ja*NL/100 + na*NL/1000);
    } /* end of loop */

    } /* end region */

    cs = 0;
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
                cs = cs + i*NL/10 + j*NL/100 + n*NL/1000 + 5;

    #pragma dvm get_actual(erria, errib, s)

    if ((erria == ER) && (errib == ER) && (s == cs))
        ansyes(tname);
    else
        ansno(tname);

    #undef AN1
    #undef AN2
    #undef AN3
    #undef BN1
    #undef BN2
    #undef BN3
}
/*  --------------------------------------------------realign333 */
    /* ALIGN arrB3[i][j][n]   WITH arrA3[i+2][j+4][n+3]
       REALIGN arrB3[i][j][n] WITH arrA3[2*i+1][2*n][j+1] */

void realign333()
{
    #define AN1 12
    #define AN2 16
    #define AN3 25
    #define BN1 4
    #define BN2 3
    #define BN3 5

/* parameters for ALIGN arrB[i][j][n] WITH arrA[k1i*i+li][k2j*j+lj][k3n*n+ln] */
    int k1i=1, li=2;
    int k2j=1, lj=4;
    int k3n=1, ln=3;
/* parameters for REALIGN arrB[i][j][n] WITH arrA[kr1i*i+lri][kr3n*n+lrn][kr2j*j+lrj] */
    int kr1i=2, lri=1;
    int kr2j=1, lrj=1;
    int kr3n=2, lrn=0;

    #pragma dvm array distribute[block][block][block]
    int A3[AN1][AN2][AN3];
    #pragma dvm array align([i][j][n] with A3[k1i*i+li][k2j*j+lj][k3n*n+ln])
    int B3[BN1][BN2][BN3];

    char tname[] = "realign333";

    erria = ER;
    errib = ER;

    #pragma dvm region inout(A3),inout(B3)
    {

//  A3 = 1;
    #pragma dvm parallel([i][j][n] on A3[i][j][n])
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
            for (n = 0; n < AN3; n++) 
                A3[i][j][n] = 1;

//  B3 = 2;
    #pragma dvm parallel([i][j][n] on B3[i][j][n])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
                B3[i][j][n] = 2;
    #pragma dvm parallel([i][j][n] on A3[i][j][n]) private(ib,jb,nb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
            for (n = 0; n < AN3; n++)
    {
                A3[i][j][n] = A3[i][j][n] + i*NL/10+j*NL/100+n*NL/1000;
                if (
                   ((i-li) == (((i-li)/k1i) * k1i)) &&
                   ((j-lj) == (((j-lj)/k2j) *k2j))  &&
                   ((n-ln) == (((n-ln)/k3n) * k3n)) &&
                   (((i-li)/k1i) >= 0)  &&
                   (((j-lj)/k2j) >= 0)  &&
                   (((n-ln)/k3n) >= 0)  &&
                   (((i-li)/k1i) < BN1)  &&
                   (((j-lj)/k2j) < BN2)  &&
                   (((n-ln)/k3n) < BN3)
                   )
                {
                    ib = (i-li)/k1i;
                    jb = (j-lj)/k2j;
                    nb = (n-ln)/k3n;
                    B3[ib][jb][nb] += ib*NL/10+jb*NL/100+nb*NL/1000;
                }
    } /* end of loop */

    } /* end region */

    #pragma dvm realign(B3[i][j][n] with A3[kr1i*i+lri][kr3n*n+lrn][kr2j*j+lrj])

    s=0;

    #pragma dvm actual (erria, errib, s)

    #pragma dvm region
    {
    #pragma dvm parallel([i][j][n] on B3[i][j][n]) reduction(min(erria),min(errib),sum(s)),private(ia,ja,na)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
    {
                s = s + B3[i][j][n];
                if (B3[i][j][n] != (i*NL/10+j*NL/100+n*NL/1000) + 2)
                    errib = Min(errib,i*NL/10 + j*NL/100 + n*NL/1000);
                ia=kr1i * i + lri;
                ja=kr3n * n + lrn;
                na=kr2j * j + lrj;
                if (A3[ia][ja][na] != (ia*NL/10+ja*NL/100+na*NL/1000)+1)
                    erria = Min(erria,ia*NL/10 + ja*NL/100 + na*NL/1000);
    } /* end of loop */

    } /* end region */

    cs = 0;
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
                cs = cs + i*NL/10 + j*NL/100 + n*NL/1000 + 2;

    #pragma dvm get_actual(erria, errib, s)

    if ((erria == ER) && (errib == ER) && (s == cs))
        ansyes(tname);
    else
        ansno(tname);

    #undef AN1
    #undef AN2
    #undef AN3
    #undef BN1
    #undef BN2
    #undef BN3
}

/*  ----------------------------------------------------realign334 */
    /* ALIGN arrB3[i][j][n] WITH arrA3[n+1][3*i+1][j+2]
       REALIGN arrB3[i][j][n] WITH arrA3[2*j][i+1][2*n+1] */

void realign334()
{
    #define AN1 15
    #define AN2 28
    #define AN3 20
    #define BN1 4
    #define BN2 6
    #define BN3 6

/* parameters for ALIGN arrB[i][j][n] WITH arrA[k3n*n+ln][k1i*i+li][k2j*j+lj] */
    int k1i=3, li=1;
    int k2j=1, lj=2;
    int k3n=1, ln=1;
/* parameters for REALIGN arrB[i][j][n] WITH arrA[kr2j*j+lrj][kr1i*i+lri][kr3n*n+lrn] */
    int kr1i=1, lri=1;
    int kr2j=2, lrj=0;
    int kr3n=2, lrn=1;

    #pragma dvm array distribute[block][block][block]
    int A3[AN1][AN2][AN3];
    #pragma dvm array align([i][j][n] with A3[k3n*n+ln][k1i*i+li][k2j*j+lj])
    int B3[BN1][BN2][BN3];

    char tname[] = "realign334";

    erria = ER;
    errib = ER;

    #pragma dvm region in(A3),in(B3),out(A3),out(B3)
    {

//  A3 = 0;
    #pragma dvm parallel([i][j][n] on A3[i][j][n])
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
            for (n = 0; n < AN3; n++)
                A3[i][j][n] = 0;

//  B3 = 0;
    #pragma dvm parallel([i][j][n] on B3[i][j][n])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
                B3[i][j][n] = 0;

    #pragma dvm parallel([i][j][n] on A3[i][j][n]) private(ib,jb,nb)
    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*NL/1000;
                if (
                   ((i-ln) == (((i-ln)/k3n) * k3n)) &&
                   ((j-li) == (((j-li)/k1i) * k1i)) &&
                   ((n-lj) == (((n-lj)/k2j) * k2j)) &&
                   (((i-ln)/k3n) >= 0) &&
                   (((j-li)/k1i) >= 0) &&
                   (((n-lj)/k2j) >= 0) &&
                   (((i-ln)/k3n) < BN3) &&
                   (((j-li)/k1i) < BN1) &&
                   (((n-lj)/k2j) < BN2)
                  )
                {
                    ib = (j-li)/k1i;
                    jb = (n-lj)/k2j;
                    nb = (i-ln)/k3n;
                    B3[ib][jb][nb] += ib*NL/10+jb*NL/100+nb*NL/1000;
                }
    } /* end of loop */

    } /* end region */

    #pragma dvm realign(B3[i][j][n] with A3[kr2j*j+lrj][kr1i*i+lri][kr3n*n+lrn])

    s=0;

    #pragma dvm actual (erria, errib, s)

    #pragma dvm region
    {
    #pragma dvm parallel([i][j][n] on B3[i][j][n]) reduction(min(erria),min(errib),sum(s)),private(ia,ja,na)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
    {
                s += B3[i][j][n];
                if (B3[i][j][n] != (i*NL/10+j*NL/100+n*NL/1000))
                    errib = Min(errib,i*NL/10 + j*NL/100 + n*NL/1000);
                ia=kr2j * j + lrj;
                ja=kr1i * i + lri;
                na=kr3n * n + lrn;
                if (A3[ia][ja][na] != (ia*NL/10+ja*NL/100+na*NL/1000))
                    erria = Min(erria,ia*NL/10 + ja*NL/100 + na*NL/1000);
    } /* end of loop */

    } /* end region */

    cs = 0;
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
                cs = cs + i*NL/10 + j*NL/100 + n*NL/1000;

    #pragma dvm get_actual(erria, errib, s)

    if ((erria == ER) && (errib == ER) && (s == cs))
        ansyes(tname);
    else
        ansno(tname);

    #undef AN1
    #undef AN2
    #undef AN3
    #undef BN1
    #undef BN2
    #undef BN3
}

/* ----------------------------------------------------realign335 */
    /* ALIGN arrB[*][*][*] WITH arrA[*][*][*]
       REALIGN arrB[i][j][n] WITH arrA[i][j][n] */

void realign335()
{
    #define AN1 10
    #define AN2 10
    #define AN3 10
    #define BN1 4
    #define BN2 8
    #define BN3 4

/* parameters for  ALIGN arrB[*][*][*] WITH arrA[*][*][*] */
    int k1i=0, li=0;
    int k2j=0, lj=0;
    int k3n=0, ln=0;
/* parameters for REALIGN arrB[i][j][n] WITH arrA[kr1i*i+lri][kr2j*j+lrj][kr3n*n+lrn] */
    int kr1i=1, lri=0;
    int kr2j=1, lrj=0;
    int kr3n=1, lrn=0;

    #pragma dvm array distribute[block][block][block]
    int A3[AN1][AN2][AN3];
    #pragma dvm array align([][][] with A3[][][])
    int B3[BN1][BN2][BN3];

    char tname[] = "realign335";

    erria = ER;
    errib = ER;

    #pragma dvm actual (A3, B3)

    #pragma dvm region inout(B3)
    {

//  A3 = 0;
    #pragma dvm parallel([i][j][n] on A3[i][j][n])
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
            for (n = 0; n < AN3; n++)
                A3[i][j][n] = 0;

//  B3 = 6;
    #pragma dvm parallel([i][j][n] on B3[i][j][n])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
                B3[i][j][n] = 6;

    #pragma dvm parallel([i][j][n] on A3[i][j][n])
    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*NL/1000;
    } 

    #pragma dvm parallel([i][j][n] on B3[i][j][n])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
    {
                 B3[i][j][n] = B3[i][j][n] + i*NL/10+j*NL/100+n*NL/1000;
    } 

    } /* end region */

    #pragma dvm realign(B3[i][j][n] with A3[kr1i*i+lri][kr2j*j+lrj][kr3n*n+lrn])

    s=0;

    #pragma dvm actual (erria, errib, s)

    #pragma dvm region inlocal(A3,B3)
    {

    #pragma dvm parallel([i][j][n] on B3[i][j][n]) reduction(min(erria),min(errib),sum(s)),private(ia,ja,na)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
    {
                s += B3[i][j][n];
                if (B3[i][j][n] != (i*NL/10+j*NL/100+n*NL/1000)+ 6)
                    errib = Min(errib,i*NL/10 + j*NL/100 + n*NL/1000);
                ia=kr1i * i + lri;
                ja=kr2j * j + lrj;
                na=kr3n * n + lrn;
                if (A3[ia][ja][na] != (ia*NL/10+ja*NL/100+na*NL/1000))
                    erria = Min(erria,ia*NL/10 + ja*NL/100 + na*NL/1000);
    } /* end of loop */

    } /* end region */

    cs = 0;
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
                cs = cs + i*NL/10 + j*NL/100 + n*NL/1000 + 6;

    #pragma dvm get_actual(erria, errib, s)

    if ((erria == ER) && (errib == ER) && (s == cs))
        ansyes(tname);
    else
        ansno(tname);

    #undef AN1
    #undef AN2
    #undef AN3
    #undef BN1
    #undef BN2
    #undef BN3
}

/*  ----------------------------------------------------realign336 */
    /* ALIGN arrB3[i][j][n] WITH arrA3[i][j+1][2*n+1]
       REALIGN arrB3[*][j][n] WITH arrA[j+1][n][1] */

void realign336()
{
    #define AN1 8
    #define AN2 8
    #define AN3 8
    #define BN1 3
    #define BN2 4
    #define BN3 3

/* parameters for ALIGN arrB[i][j][n] WITH arrA[k1i*i+li][k2j*j+lj][k3n*n+ln] */
    int k1i=1,li=0;
    int k2j=1,lj=1;
    int k3n=2,ln=1;
/* parameters for REALIGN arrB[*][i][j] WITH arrA[kr2j*j+lrj][kr3n*n+lrn][lri] */
    int kr1i=0,lri=1;
    int kr2j=1,lrj=1;
    int kr3n=1,lrn=0;

    #pragma dvm array distribute[block][block][block]
    int A3[AN1][AN2][AN3];
    #pragma dvm array align([i][j][n] with A3[k1i*i+li][k2j*j+lj][k3n*n+ln])
    int B3[BN1][BN2][BN3];

    char tname[] = "realign336";

    erria = ER;
    errib = ER;

    #pragma dvm actual (B3)

    #pragma dvm region inout(B3), inout(A3)
    {

//  B3 = 0;
    #pragma dvm parallel([i][j][n] on B3[i][j][n])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
                B3[i][j][n] = 0;

    #pragma dvm parallel([i][j][n] on A3[i][j][n]) private(ib,jb,nb)
    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*NL/1000;
                if (
                  ((i-li) == (((i-li)/k1i) * k1i)) &&
                  ((j-lj) == (((j-lj)/k2j) *k2j))  &&
                  ((n-ln) == (((n-ln)/k3n) * k3n)) &&
                  (((i-li)/k1i) >= 0)  &&
                  (((j-lj)/k2j) >= 0)  &&
                  (((n-ln)/k3n) >= 0)  &&
                  (((i-li)/k1i) < BN1)  &&
                  (((j-lj)/k2j) < BN2)  &&
                  (((n-ln)/k3n) < BN3)
                  )
                {
                    ib = (i-li)/k1i;
                    jb = (j-lj)/k2j;
                    nb = (n-ln)/k3n;
                    B3[ib][jb][nb]=ib*NL/10+jb*NL/100+nb*NL/1000;
                }
    } /* end of loop */

    } /* end region */

    #pragma dvm realign(B3[][j][n] with A3[kr2j*j+lrj][kr3n*n+lrn][lri])

    s=0;

    #pragma dvm actual (erria, errib, s)

    #pragma dvm region
    {
    #pragma dvm parallel([i][j][n] on B3[i][j][n]) reduction(min(erria), min(errib), sum(s)), private(ia, ja, na)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
    {
                s = s + B3[i][j][n];
                if (B3[i][j][n] != (i*NL/10+j*NL/100+n*NL/1000))
                    errib = Min(errib,i*NL/10 + j*NL/100+ n*NL/1000);
                ia=kr2j*j+lrj;
                ja=kr3n*n+lrn;
                na=lri;
                if (A3[ia][ja][na] != (ia*NL/10+ja*NL/100+na*NL/1000))
                    erria = Min(erria,i*NL/10 + j*NL/100+ n*NL/1000);
    } /* end of loop */

    } /* end region */

    cs = 0;
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            for (n = 0; n < BN3; n++)
                cs = cs + i*NL/10 + j*NL/100+ n*NL/1000;

    #pragma dvm get_actual(erria, errib, s)

    if ((erria == ER) && (errib == ER) && (s == cs))
        ansyes(tname);
    else
        ansno(tname);

    #undef AN1
    #undef AN2
    #undef AN3
    #undef BN1
    #undef BN2
    #undef BN3
}

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