//    TESTING OF THE REMOTE_ACCESS DIRECTIVE AND THE REMOTE_ACCESS CLAUSE'.
//    DISTRIBUTED ARRAY A(N) OR ELEMENTS OF THIS ARRAY ARE REPLICATED
//    ON ALL PROCESSORS.

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

void rem1101();
void rem1102();
void rem1103();
void rem1104();
void rem1105();
void rem1106();
void rem1107();
void rem1108();
void rem1109();
void rem1110();
void rem1111();
void rem1112();

void serial1(int *ar, int n, int nl);
void ansyes(const char *name);
void ansno(const char *name);

#define n 16
#define nl 1000
#define Min(x, y) (x < y) ? (x) : (y)

int main(int argc, char *argv[]) {
  printf("===START OF REM11========================\n");

  // --------------------------------------------------
  rem1101();

  // --------------------------------------------------
  rem1102();

  // --------------------------------------------------
  rem1103();

  // -------------------------------------------------
  rem1104();

  // -------------------------------------------------
  rem1105();

  // -------------------------------------------------
  rem1106();

  // --------------------------------------------------
  rem1107();

  // --------------------------------------------------
  rem1108();

  // --------------------------------------------------
  rem1109();

  // -------------------------------------------------
  rem1110();

  // -------------------------------------------------
  rem1111();

  // -------------------------------------------------
  rem1112();

  // -------------------------------------------------
  //
  //
  printf("=== END OF REM11 ========================= \n");
  return 0;
}

// ---------------------------------------------REM1101
void rem1101() {
#pragma dvm array distribute[*]
  int b[n];
#pragma dvm array align([i] with b[i])
  int a[n];
  int c[n];
  int nloop, i, nnl, ib;

  const char *tname = "REM1101";
  nnl = nl;
  serial1(c, n, nnl);
  nloop = nl;

#pragma dvm region out(a)
  {
#pragma dvm parallel([i] on a[i - 1])
    for (i = 1; i <= n; i++) {
      a[i - 1] = nl + i;
    }
  }
#pragma dvm get_actual(a[0])
#pragma dvm remote_access(a[0])
  { ib = a[0]; }

  if (ib == c[0]) {
    ansyes(tname);
  } else {
    ansno(tname);
  }
}

void rem1102() {
#pragma dvm array distribute[*]
  int b[n];
#pragma dvm array align([i] with b[i])
  int a[n];
  int c[n];
  int nloop, i, nnl, ib;

  const char *tname = "REM1102";
  nnl = nl;
  serial1(c, n, nnl);
  nloop = nl;

#pragma dvm region out(a)
  {
#pragma dvm parallel([i] on a[i - 1])
    for (i = 1; i <= n; i++) {
      a[i - 1] = nl + i;
    }
  }
#pragma dvm get_actual(a[n - 1])
#pragma dvm remote_access(a[n - 1])
  { ib = a[n - 1]; }

  if (ib == c[n - 1]) {
    ansyes(tname);
  } else {
    ansno(tname);
  }
}

void rem1103() {
#pragma dvm array distribute[*]
  int b[n];
#pragma dvm array align([i] with b[i])
  int a[n];
  int c[n];
  int nloop, i, nnl, ib;

  const char *tname = "REM1103";
  nnl = nl;
  serial1(c, n, nnl);
  nloop = nl;

#pragma dvm region out(a)
  {
#pragma dvm parallel([i] on a[i - 1])
    for (i = 1; i <= n; i++) {
      a[i - 1] = nl + i;
    }
  }
#pragma dvm get_actual(a[n / 2 - 1])
#pragma dvm remote_access(a[n / 2 - 1])
  { ib = a[n / 2 - 1]; }

  if (ib == c[n / 2 - 1]) {
    ansyes(tname);
  } else {
    ansno(tname);
  }
}

void rem1104() {
#pragma dvm array distribute[*]
  int b[n];
#pragma dvm array align([i] with b[i])
  int a[n];
  int c[n], d[n];
  int nloop, i, nnl, isumc, isuma;

  const char *tname = "REM1104";
  isumc = 0;
  isuma = 0;
  nnl = nl;
  serial1(c, n, nnl);
  nloop = nl;

#pragma dvm region out(a)
  {
#pragma dvm parallel([i] on a[i - 1])
    for (i = 1; i <= n; i++) {
      a[i - 1] = nl + i;
    }
  }
  for (i = 1; i <= n; i++) {
#pragma dvm get_actual(a[i - 1])
#pragma dvm remote_access(a[i - 1])
    { d[i - 1] = a[i - 1]; }
    isumc = isumc + c[i - 1];
    isuma = isuma + d[i - 1];
  }

  if (isumc == isuma) {
    ansyes(tname);
  } else {
    ansno(tname);
  }
}

void rem1105() {
#pragma dvm array distribute[*]
  int b[n];
#pragma dvm array align([i] with b[i])
  int a[n];
  int c[n], d[n];
  int nloop, i, nnl, isumc, isuma;

  const char *tname = "REM1105";
  isumc = 0;
  isuma = 0;
  nnl = nl;
  serial1(c, n, nnl);
  nloop = nl;

#pragma dvm region out(a)
  {
#pragma dvm parallel([i] on a[i - 1])
    for (i = 1; i <= n; i++) {
      a[i - 1] = nl + i;
    }
  }
#pragma dvm get_actual(a)
  for (i = 1; i <= n; i++) {
#pragma dvm remote_access(a[])
    { d[i - 1] = a[i - 1]; }
    isumc = isumc + c[i - 1];
    isuma = isuma + d[i - 1];
  }

  if (isumc == isuma) {
    ansyes(tname);
  } else {
    ansno(tname);
  }
}

void rem1106() {
#pragma dvm array distribute[*]
  int b[n];
#pragma dvm array align([i] with b[i])
  int a[n];
  int c[n], d[n];
  int nloop, i, nnl, isumc, isuma;

  const char *tname = "REM1106";
  isumc = 0;
  isuma = 0;
  nnl = nl;
  serial1(c, n, nnl);
  nloop = nl;

#pragma dvm region out(a)
  {
#pragma dvm parallel([i] on a[i - 1])
    for (i = 1; i <= n; i++) {
      a[i - 1] = nl + i;
    }
  }
  int kk = 2;
  int kk1 = 3;
  for (i = 1; i <= n / kk - kk1; i++) {
#pragma dvm get_actual(a[kk * (i - 1) + kk1])
#pragma dvm remote_access(a[kk * (i - 1) + kk1])
    { d[i - 1] = a[kk * (i - 1) + kk1]; }
    isumc = isumc + c[kk * (i - 1) + kk1];
    isuma = isuma + d[i - 1];
  }

  if (isumc == isuma) {
    ansyes(tname);
  } else {
    ansno(tname);
  }
}

void rem1107() {
#pragma dvm array distribute[*]
  int b[n];
#pragma dvm array align([i] with b[i])
  int a[n];
  int c[n];
  int nloop, i, nnl;

  const char *tname = "REM1107";
  nnl = nl;
  serial1(c, n, nnl);
  nloop = nl;

#pragma dvm region local(a, b)
  {
#pragma dvm parallel([i] on a[i - 1])
    for (i = 1; i <= n; i++) {
      a[i - 1] = nl + i;
    }

#pragma dvm parallel([i] on b[i - 1]) remote_access(a[0])
    for (i = 1; i <= n; i++) {
      b[i - 1] = a[0];
    }

#pragma dvm parallel([i] on a[i - 1]) reduction(min(nloop))
    for (i = 1; i <= n; i++) {
      if (b[i - 1] != c[0]) {
        nloop = Min(nloop, i);
      }
    }
  }
#pragma dvm get_actual(nloop)
  if (nloop == nl) {
    ansyes(tname);
  } else {
    ansno(tname);
  }
}

void rem1108() {
#pragma dvm array distribute[*]
  int b[n];
#pragma dvm array align([i] with b[i])
  int a[n];
  int c[n];
  int nloop, i, nnl;

  const char *tname = "REM1108";
  nnl = nl;
  serial1(c, n, nnl);
  nloop = nl;

#pragma dvm region local(a, b)
  {
#pragma dvm parallel([i] on a[i - 1])
    for (i = 1; i <= n; i++) {
      a[i - 1] = nl + i;
    }

#pragma dvm parallel([i] on b[i - 1]) remote_access(a[n - 1])
    for (i = 1; i <= n; i++) {
      b[i - 1] = a[n - 1];
    }

#pragma dvm parallel([i] on b[i - 1]) reduction(min(nloop))
    for (i = 1; i <= n; i++) {
      if (b[i - 1] != c[n - 1]) {
        nloop = Min(nloop, i);
      }
    }
  }
#pragma dvm get_actual(nloop)
  if (nloop == nl) {
    ansyes(tname);
  } else {
    ansno(tname);
  }
}

void rem1109() {
#pragma dvm array distribute[*]
  int b[n];
#pragma dvm array align([i] with b[i])
  int a[n];
  int c[n];
  int nloop, i, nnl;

  const char *tname = "REM1109";
  nnl = nl;
  serial1(c, n, nnl);
  nloop = nl;

#pragma dvm region local(a, b)
  {
#pragma dvm parallel([i] on a[i - 1])
    for (i = 1; i <= n; i++) {
      a[i - 1] = nl + i;
    }

#pragma dvm parallel([i] on b[i - 1]) remote_access(a[n / 2 - 1])
    for (i = 1; i <= n; i++) {
      b[i - 1] = a[n / 2 - 1];
    }

#pragma dvm parallel([i] on b[i - 1]) reduction(min(nloop))
    for (i = 1; i <= n; i++) {
      if (b[i - 1] != c[n / 2 - 1]) {
        nloop = Min(nloop, i);
      }
    }
  }
#pragma dvm get_actual(nloop)
  if (nloop == nl) {
    ansyes(tname);
  } else {
    ansno(tname);
  }
}

void rem1110() {
#pragma dvm array distribute[*]
  int b[n];
#pragma dvm array align([i] with b[i])
  int a[n];
  int c[n];
  int nloop, i, nnl;

  const char *tname = "REM1110";
  nnl = nl;
  serial1(c, n, nnl);
  nloop = nl;

#pragma dvm region local(a, b)
  {
#pragma dvm parallel([i] on a[i - 1])
    for (i = 1; i <= n; i++) {
      a[i - 1] = nl + i;
    }

#pragma dvm parallel([i] on b[i - 1]) remote_access(a[])
    for (i = 1; i <= n; i++) {
      b[i - 1] = a[i - 1];
    }

#pragma dvm parallel([i] on b[i - 1]) reduction(min(nloop))
    for (i = 1; i <= n; i++) {
      if (b[i - 1] != c[i - 1]) {
        nloop = Min(nloop, i);
      }
    }
  }
#pragma dvm get_actual(nloop)
  if (nloop == nl) {
    ansyes(tname);
  } else {
    ansno(tname);
  }
}

void rem1111() {
#pragma dvm array distribute[*]
  int b[n];
#pragma dvm array align([i] with b[i])
  int a[n];
  int c[n];
  int nloop, i, nnl;

  const char *tname = "REM1111";
  nnl = nl;
  serial1(c, n, nnl);
  nloop = nl;

#pragma dvm region local(a, b)
  {
#pragma dvm parallel([i] on a[i - 1])
    for (i = 1; i <= n; i++) {
      a[i - 1] = nl + i;
    }

#pragma dvm parallel([i] on b[i - 1]) remote_access(a[i - 1])
    for (i = 1; i <= n; i++) {
      b[i - 1] = a[i - 1];
    }

#pragma dvm parallel([i] on b[i - 1]) reduction(min(nloop))
    for (i = 1; i <= n; i++) {
      if (b[i - 1] != c[i - 1]) {
        nloop = Min(nloop, i);
      }
    }
  }
#pragma dvm get_actual(nloop)
  if (nloop == nl) {
    ansyes(tname);
  } else {
    ansno(tname);
  }
}

void rem1112() {
#pragma dvm array distribute[*]
  int b[n];
#pragma dvm array align([i] with b[i])
  int a[n];
  int c[n];
  int nloop, i, nnl;

  const char *tname = "REM1112";
  nnl = nl;
  serial1(c, n, nnl);
  nloop = nl;
  int kk = 2;
  int kk1 = 3;

#pragma dvm region local(a, b)
  {
#pragma dvm parallel([i] on a[i - 1])
    for (i = 1; i <= n; i++) {
      a[i - 1] = nl + i;
    }

#pragma dvm parallel([i] on b[i - 1]) remote_access(a[kk * i + (kk1 - kk)])
    for (i = 1; i <= n / kk - kk1; i++) {
      b[i - 1] = a[kk * i + (kk1 - kk)];
    }

#pragma dvm parallel([i] on b[i - 1]) reduction(min(nloop))
    for (i = 1; i <= n / kk - kk1; i++) {
      if (b[i - 1] != c[kk * (i - 1) + kk1]) {
        nloop = Min(nloop, i);
      }
    }
  }
#pragma dvm get_actual(nloop)
  if (nloop == nl) {
    ansyes(tname);
  } else {
    ansno(tname);
  }
}

#undef n
#undef nl

void serial1(int *ar, int n, int nl) {
  int i;
  for (i = 1; i <= n; i++) {
    ar[i - 1] = nl + i;
  }
}

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

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