/*    REALIGN22
Testing REALIGN directive */

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

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

static void realign221();
static void realign222();
static void realign223();
static void realign224();
static void realign225();
static void realign226();
static void realign227();
static void realign228();
static void realign229();

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, erria, errib, i, j, k, n, ia, ja, ib, jb;

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

    /* ALIGN arrB[i][j] WITH arrA[i][j]
       REALIGN arrB[i][j] WITH arrA[3*i+2][2*j+1] */
    realign221();
    /* ALIGN arrB[i][j] WITH arrA[j+1][i]
       REALIGN arrB[i][j] WITH arrA[i+4][j] */
    realign222();
    /* ALIGN arrB[i][*] WITH arrA[*][i]
       REALIGN arrB[i][j] WITH arrA[i+4][j+4] */
    realign223();
    /* ALIGN arrB[*][*] WITH arrA[*][1]
       REALIGN arrB[i][j] WITH arrA[i+4][j+4] */
    realign224();
    /* ALIGN arrB[i][j] WITH arrA[i][j]
       REALIGN arrB[*][*] WITH arrA[*][2] */
    realign225();
    /* ALIGN arrB[i][j] WITH arrA[i][j]
       REALIGN arrB[i][j] WITH arrA[2*j+1][3*i+2] */
    realign226();
    /* ALIGN arrB[*][*] WITH arrA[4][*]
       REALIGN arrB[i][j] WITH arrA[i+2][2*j] */
    realign227();
    /* ALIGN arrB[i][j] WITH arrA[j][i]
       REALIGN arrB[*][*] WITH arrA[3][*] */
    realign228();
    /* ALIGN arrB[i][j] WITH arrA[2*i][3*j+1]
       REALIGN arrB[i][j] WITH arrA[j+6][i+2] */
    realign229();

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

/* ---------------------------------------------REALIGN221 */
        /* ALIGN arrB[i][j] WITH arrA[i][j]
           REALIGN arrB[i][j] WITH arrA[3*i+2][2*j+1] */
void realign221()
{
    #define AN1 16
    #define AN2 16
    #define BN1 4
    #define BN2 4

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

    #pragma dvm array distribute[block][block]
    int A2[AN1][AN2];
    #pragma dvm array align([i][j] with A2[k1i * i + li][k2j * j + lj])
    int B2[BN1][BN2];

    char tname[] = "realign221";

    erria = ER;
    errib = ER;

    #pragma dvm region in(A2,B2), out(A2,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] on A2[i][j]) private(ib,jb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
        {
            A2[i][j] = (i*NL+j)*2;
            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)/k2j) < BN2)
               )
               {
                    ib = (i-li)/k1i;
                    jb = (j-lj)/k2j;
                    B2[ib][jb]= B2[ib][jb] + ib*NL+jb;
               }
       }

    } /* end region */

    #pragma dvm realign(B2[i][j] with A2[kr1i * i + lri][kr2j * j + lrj])

    #pragma dvm actual (erria, errib)

    #pragma dvm region in(A2,B2), local(A2,B2)
    {
    #pragma dvm parallel([i][j] on B2[i][j]) reduction(min(erria),min(errib)), private(ia,ja)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
        {
            if (B2[i][j] != (i*NL+j))
                errib = Min(errib, i*NL/10+j);

            ia=kr1i * i + lri;
            ja=kr2j * j + lrj;
            if (A2[ia][ja] != (ia*NL+ja)*2)
                erria = Min(erria, i*NL/10+j);
        }

    } /* end region */

    #pragma dvm get_actual(erria, errib)

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

    #undef AN1
    #undef AN2
    #undef BN1
    #undef BN2
}
/* ---------------------------------------------REALIGN222 */
        /* ALIGN arrB[i][j] WITH arrA[j+1][i]
           REALIGN arrB[i][j] WITH arrA[i+4][j] */
void realign222()
{
    #define AN1 8
    #define AN2 8
    #define BN1 4
    #define BN2 4

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

    #pragma dvm array distribute[block][block]
    int A2[AN1][AN2];
    #pragma dvm array align([i][j] with A2[k2j * j + lj][k1i * i + li])
    int B2[BN1][BN2];

    char tname[] = "realign222";

    erria = ER;
    errib = ER;

    #pragma dvm region inout(A2,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] = 1;

    #pragma dvm parallel([i][j] on A2[i][j]) private(ib), private(jb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
        {
            A2[i][j] = i*NL+j;
            if (
                ((i-lj) ==(((i-lj)/k2j) * k2j)) &&
                ((j-li) ==(((j-li)/k1i) *k1i)) &&
                (((i-lj)/k2j) >= 0)  &&
                (((j-li)/k1i) >= 0)  &&
                (((i-lj)/k2j) < BN2)  &&
                (((j-li)/k1i) < BN1)
               )
               {
                     ib = (j-li)/k1i;
                     jb = (i-lj)/k2j;
                     B2[ib][jb]=B2[ib][jb]+ib*NL+jb;
               }
        }

    } /* end region */

    #pragma dvm realign(B2[i][j] with A2[kr1i * i + lri][kr2j * j + lrj])

    #pragma dvm actual (erria, errib)

    #pragma dvm region
    {
    #pragma dvm parallel([i][j] on B2[i][j]) private(ia,ja), reduction(min(erria),min(errib))
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
        {
            if (B2[i][j] != (i*NL+j)+1)
                errib = Min(errib, i*NL/10+j);
            ia=kr1i * i + lri;
            ja=kr2j * j + lrj;
            if (A2[ia][ja] != (ia*NL+ja))
                erria = Min(erria, i*NL/10+j);
        }

    } /* end region */

    #pragma dvm get_actual(erria, errib)

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

    #undef AN1
    #undef AN2
    #undef BN1
    #undef BN2
}
/* ---------------------------------------------REALIGN223 */
        /* ALIGN arrB[i][*] WITH arrA[*][i]
           REALIGN arrB[i][j] WITH arrA[i+4][j+4] */
void realign223()
{
    #define AN1 10
    #define AN2 10
    #define BN1 4
    #define BN2 4

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

    #pragma dvm array distribute[block][block]
    int A2[AN1][AN2];
    #pragma dvm array align([i][] with A2[][k1i * i + li])
    int B2[BN1][BN2];

    char tname[] = "realign223";

    erria = ER;
    errib = ER;

    #pragma dvm actual (errib)

    #pragma dvm region
    {
    #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+j+5;

    #pragma dvm parallel([i][j] on A2[i][j]) private(ib,jb,k), reduction (min(errib))
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
        {
            A2[i][j] = i*NL+j;
            for (k = 0; k < BN2; k++)
            {
                if (
                     ((j-li) ==(((j-li)/k1i) *k1i)) &&
                     (((j-li)/k1i) >= 0)  &&
                     (((j-li)/k1i) < BN1)
                    )
                {
                    ib = ((j-li)/k1i);
                    jb = k;
                    if (B2[ib][jb] !=(ib*NL+jb+5))
                        errib = Min(errib, i*NL/10+j);
                }
            }
        }

    } /* end region */

    #pragma dvm realign(B2[i][j] with A2[kr1i * i + lri][kr2j * j + lrj])

    #pragma dvm get_actual (errib)
    #pragma dvm actual (erria, errib)

    #pragma dvm region
    {
    #pragma dvm parallel([i][j] on B2[i][j]) reduction(min(erria), min(errib)), private(ia,ja)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
        {
            if (B2[i][j] != (i*NL+j+5))
                errib = Min(errib, i*NL/10+j);
            ia=kr1i * i + lri;
            ja=kr2j * j + lrj;
            if (A2[ia][ja] != (ia*NL+ja))
                erria = Min(erria, i*NL/10+j);
        }

    } /* end region */

    #pragma dvm get_actual(erria, errib)

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

    #undef AN1
    #undef AN2
    #undef BN1
    #undef BN2
}
/* ---------------------------------------------REALIGN224 */
        /* ALIGN arrB[*][*] WITH arrA[*][1]
           ALIGN arrB[i][j] WITH arrA[i+4][j+4] shift along i and j */
void realign224()
{
    #define AN1 12
    #define AN2 14
    #define BN1 5
    #define BN2 6

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

    #pragma dvm array distribute[block][block]
    int A2[AN1][AN2];
    #pragma dvm array align([][] with A2[][k2j * j + lj])
    int B2[BN1][BN2];

    char tname[] = "realign224";

    erria = ER;
    errib = ER;

    #pragma dvm actual (errib)

    #pragma dvm region inout(A2,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+j)*2;

    #pragma dvm parallel([i][j] on A2[i][j]) private(ib,jb,k,n), reduction(min(errib))
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
        {
            A2[i][j] = i*NL+j+5;
            if (j == (lj))
                for (k = 0; k < BN1; k++)
                    for (n = 0; n < BN2; n++)
                    {
                        ib = k;
                        jb = n;
                        if (B2[ib][jb] !=(ib*NL+jb)*2)
                             errib = Min(errib, i*NL/10+j);
                    }
        }

    } /* end region */

    #pragma dvm realign(B2[i][j] with A2[kr1i * i + lri][kr2j * j + lrj])

    #pragma dvm get_actual (errib)
    #pragma dvm actual (erria, errib)

    #pragma dvm region
    {
    #pragma dvm parallel([i][j] on B2[i][j]) reduction(min(erria), min(errib)), private(ia,ja)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
        {
            if (B2[i][j] != (i*NL+j)*2)
                   errib = Min(errib, i*NL/10+j);
            ia=kr1i * i + lri;
            ja=kr2j * j + lrj;
            if (A2[ia][ja] != (ia*NL+ja+5))
                   erria = Min(erria, i*NL/10+j);
        }

    } /* end region */

    #pragma dvm get_actual(erria, errib)

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

    #undef AN1
    #undef AN2
    #undef BN1
    #undef BN2
}
/* ---------------------------------------------REALIGN225 */
        /* ALIGN arrB[i][j] WITH arrA[i][j]
           REALIGN arrB[*][*] WITH arrA[*][2] */
void realign225()
{
    #define AN1 10
    #define AN2 10
    #define BN1 4
    #define BN2 4

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

    #pragma dvm array distribute[block][block]
    int A2[AN1][AN2];
    #pragma dvm array align([i][j] with A2[k1i * i + li][k2j * j + lj])
    int B2[BN1][BN2];

    char tname[] = "realign225";

    errib = ER;

    #pragma dvm region
    {
    #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] on A2[i][j]) private(ib,jb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
        {
            A2[i][j] = i*NL+j;
            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)/k2j) < BN2)
                  )
            {
                ib = (i-li)/k1i;
                jb = (j-lj)/k2j;
                B2[ib][jb]=ib*NL+jb;
            }
        }

    } /* end region */

    #pragma dvm realign(B2[][] with A2[][kr2j * j + lrj])

    #pragma dvm actual (errib)

    #pragma dvm region
    {
    #pragma dvm parallel([i][j] on B2[i][j]) reduction (min(errib))
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            if (B2[i][j] != (i*NL+j))
                errib = Min(errib, i*NL/10+j);

    } /* end region */

    #pragma dvm get_actual(errib)

    if (errib == ER)
        ansyes(tname);
    else
        ansno(tname);

    #undef AN1
    #undef AN2
    #undef BN1
    #undef BN2
}
/* ---------------------------------------------REALIGN226 */
    /* ALIGN arrB[i][j] WITH arrA[i][j]
       REALIGN arrB[i][j] WITH arrA[2*j+1][3*i+2] */
void realign226()
{
    #define AN1 16
    #define AN2 18
    #define BN1 6
    #define BN2 4

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

    #pragma dvm array distribute[block][block]
    int A2[AN1][AN2];
    #pragma dvm array align([i][j] with A2[k1i * i + li][k2j * j + lj])
    int B2[BN1][BN2];

    char tname[] = "realign226";

    erria = ER;
    errib = ER;

    #pragma dvm region inout(A2), in(B2), out(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;

    } /* end region */

    #pragma dvm region
    {
    #pragma dvm parallel([i][j] on A2[i][j]) private(ib,jb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
        {
            A2[i][j] = (i*NL+j)*3;
            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)/k2j) < BN2)
                )
            {
                ib = (i-li)/k1i;
                jb = (j-lj)/k2j;
                B2[ib][jb]=ib*NL+jb;
            }
        }

    } /* end region */

    #pragma dvm realign(B2[i][j] with A2[kr2j*j+lrj][kr1i*i+lri])

    #pragma dvm actual (erria, errib)

    #pragma dvm region
    {
    #pragma dvm parallel([i][j] on B2[i][j]) reduction(min(erria),min(errib)),private(ia,ja)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
        {
            if (B2[i][j] != (i*NL+j))
                errib = Min(errib, i*NL/10+j);
            ia=kr2j * j + lrj;
            ja=kr1i * i + lri;
            if (A2[ia][ja] != (ia*NL+ja)*3)
                erria = Min(erria,i*NL/10+j);
        }

    } /* end region */

    #pragma dvm get_actual(errib)

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

    #undef AN1
    #undef AN2
    #undef BN1
    #undef BN2
}
/* ---------------------------------------------REALIGN227 */
    /* ALIGN B2[*][*] WITH arrA[4][*]
       REALIGN B2[i][j] WITH arrA[i+2][2*j] */
void realign227()
{
    int AN1 = 10;
    int AN2 = 12;
    int BN1 = 4;
    int BN2 = 6;

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

    char tname[] = "realign227";

    #pragma dvm array distribute[block][block]
    int (*A2)[AN2];
    #pragma dvm array
    int (*B2)[BN2];

    A2 = malloc(sizeof(int[AN1][AN2]));
    B2 = malloc(sizeof(int[BN1][BN2]));

    #pragma dvm realign(B2[][] with A2[li][])

    erria = ER;
    errib = ER;

    #pragma dvm region
    {
    #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([j][i] on A2[i][j]) private(ib, jb, k, n)
    for (j = 0; j < AN2; j++)
        for (i = 0; i < AN1; i++)
        {
            A2[i][j] = i * NL + j + 4;
            if (i == li)
                for (k = 0; k < BN1; k++)
                    for (n = 0; n < BN2; n++)
                    {
                        ib = k;
                        jb = n;
                        B2[ib][jb] = ib * NL + jb + 7;
                    }
        }
    }

    #pragma dvm realign(B2[i][j] with A2[kr1i * i + lri][kr2j * j + lrj])

    #pragma dvm actual (erria, errib)

    #pragma dvm region
    {
    #pragma dvm parallel([i][j] on B2[i][j]) reduction(min(erria), min(errib)), private(ia, ja)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
        {
            if (B2[i][j] != (i * NL + j + 7))
                errib = Min(errib, i*NL/10+j);
            ia = kr1i * i + lri;
            ja = kr2j * j + lrj;
            if (A2[ia][ja] != (ia * NL + ja + 4))
                erria = Min(erria, i*NL/10+j);
        }
    }

    #pragma dvm get_actual(erria, errib)

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

    free(B2);
    free(A2);
}
/* ---------------------------------------------REALIGN228 */
    /* ALIGN arrB[i][j] WITH arrA[j][i]
       REALIGN arrB[*][*] WITH arrA[3][*] */
void realign228()
{
    int AN1 = 14;
    int AN2 = 8;
    int BN1 = 4;
    int BN2 = 3;

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

    char tname[] = "realign228";

    #pragma dvm array distribute[block][block]
    int (*A2)[AN2];
    #pragma dvm array
    int (*B2)[BN2];

    A2 = malloc(sizeof(int[AN1][AN2]));
    B2 = malloc(sizeof(int[BN1][BN2]));

    #pragma dvm realign(B2[i][j] with A2[k2j * j + lj][k1i * i + li])

    erria = ER;
    errib = ER;

    #pragma dvm region
    {
    #pragma dvm parallel([i][j] on B2[i][j])
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            B2[i][j] = 1;
    #pragma dvm parallel([i][j] on A2[i][j]) private(ib, jb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
        {
            A2[i][j] = i * NL + j;
            if (
                ((i-lj) ==(((i-lj)/k2j) * k2j)) &&
                ((j-li) ==(((j-li)/k1i) * k1i)) &&
                (((i-lj)/k2j) >= 0)  &&
                (((j-li)/k1i) >= 0)  &&
                (((i-lj)/k2j) < BN2)  &&
                (((j-li)/k1i) < BN1)
               )
            {
                ib = (j-li)/k1i;
                jb = (i-lj)/k2j;
                B2[ib][jb] += ib*NL+jb;
            }
        }
    }

    #pragma dvm realign(B2[][] with A2[lri][])

    #pragma dvm actual(errib)

    #pragma dvm region
    {
    #pragma dvm parallel([i][j] on B2[i][j]) reduction(min(errib))
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
            if (B2[i][j] != i * NL + j + 1)
                errib = Min(errib, i*NL/10+j);
    }

    #pragma dvm get_actual(errib)

    if (errib == ER)
        ansyes(tname);
    else
        ansno(tname);

    free(B2);
    free(A2);
}
/* ---------------------------------------------REALIGN229 */
    /* ALIGN B2[i][j] WITH arrA[2*i][3*j+1]
       REALIGN B2[i][j] WITH arrA[j+6][i+2] */
void realign229()
{
    int AN1 = 12;
    int AN2 = 18;
    int BN1 = 4;
    int BN2 = 6;

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

    char tname[] = "realign229";

    #pragma dvm array distribute[block][block]
    int (*A2)[AN2];
    #pragma dvm array
    int (*B2)[BN2];

    A2 = malloc(sizeof(int[AN1][AN2]));
    B2 = malloc(sizeof(int[BN1][BN2]));

    #pragma dvm realign(B2[i][j] with A2[k1i * i + li][k2j * j + lj])

    erria = ER;
    errib = ER;

    #pragma dvm region
    {
    #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] on A2[i][j]) private(ib, jb)
    for (i = 0; i < AN1; i++)
        for (j = 0; j < AN2; j++)
        {
            A2[i][j] = i * NL + j;
            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) / k2j) < BN2))
            {
                ib = (i - li) / k1i;
                jb = (j - lj) / k2j;
                B2[ib][jb] = ib * NL + jb;
            }
        }
    }

    #pragma dvm realign(B2[i][j] with A2[kr2j * j + lrj][kr1i * i + lri])

    #pragma dvm actual (erria, errib)

    #pragma dvm region
    {
    #pragma dvm parallel([i][j] on B2[i][j]) reduction(min(erria), min(errib)), private(ia, ja)
    for (i = 0; i < BN1; i++)
        for (j = 0; j < BN2; j++)
        {
            if (B2[i][j] != (i * NL + j))
                errib = Min(errib, i*NL/10+j);
            ia=kr2j * j + lrj;
            ja=kr1i * i + lri;
            if (A2[ia][ja] != (ia * NL + ja))
                erria = Min(erria, i*NL/10+j);
         }
    }

    #pragma dvm get_actual(erria, errib)

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

    free(B2);
    free(A2);
}

/*-------------------------------------------------------*/

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

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