/*  TESTING OF THE REMOTE_ACCESS DIRECTIVE AND THE REMOTE_ACCESS CLAUSE'.
    DISTRIBUTED ARRAY A(N,M) OR ELEMENTS OF THIS ARRAY ARE REPLICATED
    ON ALL PROCESSORS. */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define N 16
#define M 8
#define NL 1000

static void rem2101();
static void rem2102();
static void rem2103();
static void rem2104();
static void rem2105();
static void rem2106();
static void rem2107();
static void rem2108();
static void rem2109();
static void rem2110();
static void rem2111();
static void rem2112();
static void rem2113();
static void rem2114();
static void rem2115();
static void rem2116();
static void rem2117();
static void rem2118();
static void rem2119();
static void rem2120();
static void serial2(int AR[N][M], int NN, int NM, int NNL);
static void ansyes(const char tname[]);
static void ansno(const char tname[]);

int main(int an, char **as) {
  printf("===START OF REM21========================\n");
  rem2101();
  rem2102();
  rem2103();
  rem2104();
  rem2105();
  rem2106();
  rem2107();
  rem2108();
  rem2109();
  rem2110();
  rem2111();
  rem2112();
  rem2113();
  rem2114();
  rem2115();
  rem2116();
  rem2117();
  rem2118();
  rem2119();
  rem2120();

  printf("=== END OF REM21 ========================= \n");
  return 0;
}
/* ---------------------------------------------REM2101  */
void rem2101() {

  int C[N][M];
  int nloop, ib;
  char tname[] = "REM2101";
  int i, j, NN, NM, NNL;

#pragma dvm array distribute[block][block]
  int B[N][M];
#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];

  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;

#pragma dvm region out(A)
  {

#pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        A[i][j] = NL + i + j;
      }
  }
#pragma dvm get_actual(A[0][0])
#pragma dvm remote_access(A[0][0])
  { ib = A[0][0]; }
  if (ib == C[0][0])
    ansyes(tname);
  else
    ansno(tname);
  return;
}

/* ---------------------------------------------REM2102  */
void rem2102() {

  int C[N][M];
  int nloop, ib;
  char tname[] = "REM2102";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];

  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;
#pragma dvm region out(A)
  {

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

#pragma dvm get_actual(A[N - 1][M - 1])
#pragma dvm remote_access(A[N - 1][M - 1])
  { ib = A[N - 1][M - 1]; }
  if (ib == C[N - 1][M - 1])
    ansyes(tname);
  else
    ansno(tname);
  return;
}

/* ---------------------------------------------REM2103  */
void rem2103() {

  int C[N][M];
  int nloop, ib;
  char tname[] = "REM2103";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];

  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;

#pragma dvm region out(A)
  {

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

#pragma dvm get_actual(A[0][M - 1])
#pragma dvm remote_access(A[0][M - 1])
  { ib = A[0][M - 1]; }
  if (ib == C[0][M - 1])
    ansyes(tname);
  else
    ansno(tname);
}
/* ---------------------------------------------REM2104  */
void rem2104() {

  int C[N][M];
  int nloop, ib;
  char tname[] = "REM2104";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];

  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;

#pragma dvm region out(A)
  {

#pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        A[i][j] = NL + i + j;
      }
  }
#pragma dvm get_actual(A[N - 1][0])
#pragma dvm remote_access(A[N - 1][0])
  { ib = A[N - 1][0]; }
  if (ib == C[N - 1][0])
    ansyes(tname);
  else
    ansno(tname);
}

/* ---------------------------------------------REM2105  */
void rem2105() {

  int C[N][M], D[N][M];
  int ib, isuma, isumc;
  char tname[] = "REM2105";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with A[i][j])
  int B[N][M];
  isuma = 0;
  isumc = 0;
  NNL = NL;
  serial2(C, N, M, NNL);
#pragma dvm region out(A)
  {

#pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        A[i][j] = NL + i + j;
      }
  }
#pragma dvm get_actual(A[][])
  for (i = 0; i < N; i++)
    for (j = 0; j < M; j++) {
#pragma dvm remote_access(A[][])
      { D[i][j] = A[i][j]; }
      isumc = isumc + C[i][j];
      isuma = isuma + D[i][j];
    }
  if (isuma == isumc)
    ansyes(tname);
  else
    ansno(tname);
}

/* ---------------------------------------------REM2106  */
void rem2106() {

  int C[N][M], D[N][M];
  int ib, isuma, isumc;
  char tname[] = "REM2106";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with A[i][j])
  int B[N][M];
  isuma = 0;
  isumc = 0;
  NNL = NL;
  serial2(C, N, M, NNL);
#pragma dvm region out(A)
  {

#pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        A[i][j] = NL + i + j;
      }
  }
#pragma dvm get_actual(A[][0])
  for (i = 0; i < N; i++) {
#pragma dvm remote_access(A[][0])
    { D[i][0] = A[i][0]; }
    isumc = isumc + C[i][0];
    isuma = isuma + D[i][0];
  }
  if (isuma == isumc)
    ansyes(tname);
  else
    ansno(tname);
}

/* ---------------------------------------------REM2107  */
void rem2107() {

  int C[N][M], D[N][M];
  int isuma, isumc;
  char tname[] = "REM2107";

  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with A[i][j])
  int B[N][M];
  isuma = 0;
  isumc = 0;
  NNL = NL;
  serial2(C, N, M, NNL);

#pragma dvm region out(A)
  {

#pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        A[i][j] = NL + i + j;
      }
  }
#pragma dvm get_actual(A[0][])
  for (j = 0; j < M; j++) {
#pragma dvm remote_access(A[0][])
    { D[0][j] = A[0][j]; }
    isumc = isumc + C[0][j];
    isuma = isuma + D[0][j];
  }

  if (isuma == isumc)
    ansyes(tname);
  else
    ansno(tname);
}
/* ---------------------------------------------REM2108  */
void rem2108() {

  int C[N][M], D[N][M];
  int nloop, ib, isuma, isumc;
  char tname[] = "REM2108";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];
  isuma = 0;
  isumc = 0;
  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;
#pragma dvm region out(A)
  {

#pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        A[i][j] = NL + i + j;
      }
  }
#pragma dvm get_actual(A[][M - 1])

  for (i = 0; i < N; i++) {
#pragma dvm remote_access(A[][M - 1])
    { D[i][M - 1] = A[i][M - 1]; }
    isumc = isumc + C[i][M - 1];
    isuma = isuma + D[i][M - 1];
  }
  if (isuma == isumc)
    ansyes(tname);
  else
    ansno(tname);
}
/* ---------------------------------------------REM2109  */
void rem2109() {

  int C[N][M], D[N][M];
  int nloop, ib, isuma, isumc;
  char tname[] = "REM2109";

  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];
  isuma = 0;
  isumc = 0;
  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;
#pragma dvm region out(A)
  {

#pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        A[i][j] = NL + i + j;
      }
  }
#pragma dvm get_actual(A[N - 1][])
  for (j = 0; j < M; j++) {
#pragma dvm remote_access(A[N - 1][])
    { D[N - 1][j] = A[N - 1][j]; }
    isumc = isumc + C[N - 1][j];
    isuma = isuma + D[N - 1][j];
  }

  if (isuma == isumc)
    ansyes(tname);
  else
    ansno(tname);
}
/* ---------------------------------------------REM2110  */
void rem2110() {

  int C[N][M], D[N][M];
  int nloop, ib, isuma, isumc;
  char tname[] = "REM2110";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];
  isuma = 0;
  isumc = 0;
  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;

#pragma dvm region out(A)
  {

#pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        A[i][j] = NL + i + j;
      }
  }
#pragma dvm get_actual(A[][])
  for (i = 0; i < N; i++)
    for (j = 0; j < M; j++) {
#pragma dvm remote_access(A[i][j])
      { D[i][j] = A[i][j]; }
      isumc = isumc + C[i][j];
      isuma = isuma + D[i][j];
    }
  if (isuma == isumc)
    ansyes(tname);
  else
    ansno(tname);
}
/* ---------------------------------------------REM2111  */
void rem2111() {

  int C[N][M], D[N][M];
  int nloop, ib, isuma, isumc, kk, kk1;
  char tname[] = "REM2111";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];
  isuma = 0;
  isumc = 0;
  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;
#pragma dvm region out(A)
  {

#pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        A[i][j] = NL + i + j;
      }
  }
#pragma dvm get_actual(A[][])

  kk = 2;
  kk1 = 3;

  for (i = 0; i < N / (kk - kk1); i++)
    for (j = 0; j < M / (kk - kk1); j++) {
#pragma dvm remote_access(A[kk * i + kk1][kk * j + kk1])
      { D[i][j] = A[kk * i + kk1][kk * j + kk1]; }
      isumc = isumc + C[kk * i + kk1][kk * j + kk1];
      isuma = isuma + D[i][j];
    }
  if (isuma == isumc)
    ansyes(tname);
  else
    ansno(tname);
}
/* ---------------------------------------------REM2112  */
void rem2112() {

  int C[N][M];
  int nloop, ib;
  char tname[] = "REM2112";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];

  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;
#pragma dvm region local(A, B)
  {

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

#pragma dvm parallel([i][j] on B[i][j]) remote_access(A[0][0])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        B[i][j] = A[0][0];
      }
#pragma dvm parallel([i][j] on B[i][j]) reduction(min(nloop))
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        if (B[i][j] != C[0][0])
          nloop = i;
      }
  }
#pragma dvm get_actual(nloop)
  if (nloop == NL)
    ansyes(tname);
  else
    ansno(tname);
}

/* ---------------------------------------------REM2113  */
void rem2113() {

  int C[N][M];
  int nloop, ib;
  char tname[] = "REM2113";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];

  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;
#pragma dvm region local(A, B)
  {
#pragma dvm parallel([i][j] on A[i][j])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        A[i][j] = NL + i + j;
      }
#pragma dvm parallel([i][j] on B[i][j]) remote_access(A[N - 1][M - 1])
  for (i = 0; i < N; i++)
    for (j = 0; j < M; j++) {
      B[i][j] = A[N - 1][M - 1];
    }
#pragma dvm parallel([i][j] on B[i][j]) reduction(min(nloop))
  for (i = 0; i < N; i++)
    for (j = 0; j < M; j++) {
      if (B[i][j] != C[N - 1][M - 1])
        nloop = i;
    }
  }
#pragma dvm get_actual(nloop)
  if (nloop == NL)
    ansyes(tname);
  else
    ansno(tname);
}
/* ---------------------------------------------REM2114  */
void rem2114() {

  int C[N][M];
  int nloop, ib;
  char tname[] = "REM2114";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];

  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;
#pragma dvm region local(A, B)
  {

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

#pragma dvm parallel([i][j] on B[i][j]) remote_access(A[0][M - 1])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        B[i][j] = A[0][M - 1];
      }
#pragma dvm parallel([i][j] on B[i][j]) reduction(min(nloop))
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        if (B[i][j] != C[0][M - 1])
          nloop = i;
      }
  }
#pragma dvm get_actual(nloop)
  if (nloop == NL)
    ansyes(tname);
  else
    ansno(tname);
}

/* ---------------------------------------------REM2115  */
void rem2115() {

  int C[N][M];
  int nloop, ib;
  char tname[] = "REM2115";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];

  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;
#pragma dvm region local(A, B)
  {

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

#pragma dvm parallel([i][j] on B[i][j]) remote_access(A[N - 1][0])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        B[i][j] = A[N - 1][0];
      }
#pragma dvm parallel([i][j] on B[i][j]) reduction(min(nloop))
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        if (B[i][j] != C[N - 1][0])
          nloop = i;
      }
  }
#pragma dvm get_actual(nloop)
  if (nloop == NL)
    ansyes(tname);
  else
    ansno(tname);
}

/* ---------------------------------------------REM2116  */
void rem2116() {

  int C[N][M];
  int nloop, ib;
  char tname[] = "REM2116";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];

  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;
#pragma dvm region local(A, B)
  {

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

#pragma dvm parallel([i][j] on B[i][j]) remote_access(A[][])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        B[i][j] = A[i][j];
      }
#pragma dvm parallel([i][j] on B[i][j]) reduction(min(nloop))
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        if (B[i][j] != C[i][j])
          nloop = i;
      }
  }
#pragma dvm get_actual(nloop)
  if (nloop == NL)
    ansyes(tname);
  else
    ansno(tname);
}

/* ---------------------------------------------REM2117  */
void rem2117() {

  int C[N][M];
  int nloop, ib;
  char tname[] = "REM2117";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];

  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;
#pragma dvm region local(A, B)
  {

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

#pragma dvm parallel([i][j] on B[i][j]) remote_access(A[][0])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        B[i][j] = A[i][0];
      }
#pragma dvm parallel([i][j] on B[i][j]) reduction(min(nloop))
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        if (B[i][j] != C[i][0])
          nloop = i;
      }
  }
#pragma dvm get_actual(nloop)
  if (nloop == NL)
    ansyes(tname);
  else
    ansno(tname);
}
/* ---------------------------------------------REM2118  */
void rem2118() {

  int C[N][M];
  int nloop, ib;
  char tname[] = "REM2118";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];

  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;
#pragma dvm region local(A, B)
  {

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

#pragma dvm parallel([i][j] on B[i][j]) remote_access(A[0][])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        B[i][j] = A[0][j];
      }
#pragma dvm parallel([i][j] on B[i][j]) reduction(min(nloop))
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        if (B[i][j] != C[0][j])
          nloop = i;
      }
  }
#pragma dvm get_actual(nloop)
  if (nloop == NL)
    ansyes(tname);
  else
    ansno(tname);
}
/* ---------------------------------------------REM2119  */
void rem2119() {

  int C[N][M];
  int nloop, ib;
  char tname[] = "REM2119";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];

  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;
#pragma dvm region local(A, B)
  {

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

#pragma dvm parallel([i][j] on B[i][j]) remote_access(A[][M - 1])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        B[i][j] = A[i][M - 1];
      }
#pragma dvm parallel([i][j] on B[i][j]) reduction(min(nloop))
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        if (B[i][j] != C[i][M - 1])
          nloop = i;
      }
  }
#pragma dvm get_actual(nloop)
  if (nloop == NL)
    ansyes(tname);
  else
    ansno(tname);
}
/* ---------------------------------------------REM2120  */
void rem2120() {

  int C[N][M];
  int nloop, ib;
  char tname[] = "REM2120";
  int i, j, NN, NM, NNL;

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

#pragma dvm array align([i][j] with B[i][j])
  int A[N][M];

  NN = N;
  NM = M;
  NNL = NL;
  serial2(C, NN, NM, NNL);
  nloop = NL;
#pragma dvm region local(A, B)
  {

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

#pragma dvm parallel([i][j] on B[i][j]) remote_access(A[N - 1][])
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        B[i][j] = A[N - 1][j];
      }
#pragma dvm parallel([i][j] on B[i][j]) reduction(min(nloop))
    for (i = 0; i < N; i++)
      for (j = 0; j < M; j++) {
        if (B[i][j] != C[N - 1][j])
          nloop = i;
      }
  }
#pragma dvm get_actual(nloop)
  if (nloop == NL)
    ansyes(tname);
  else
    ansno(tname);
}

void serial2(int AR[N][M], int NN, int NM, int NNL) {
  int i, j;

  for (i = 0; i < NN; i++)
    for (j = 0; j < NM; j++) {
      AR[i][j] = NNL + i + j;
    }
  return;
}

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