old_contents:
use myrecord;

proc myfunction() {

  var A:[1..10] R;

  for i in 1..10 {
    A[i].verify();
    A[i].init(x=i);
    A[i].verify();
    assert(A[i].x == i);
  }
}

myfunction();

new_contents:
use myrecord;

proc myfunction() {

  var A:[1..10] R;

  for i in 1..10 {
    A[i].verify();
    A[i].init(x=i);
    A[i].verify();
    assert(A[i].x == i);
  }

  var B:[1..10] R;

  B = A;

  for i in 1..10 {
    B[i].verify();
    assert(B[i].x == i);
  }

}

myfunction();

subject: Fix whole array assign test

message: Fix whole array assign test


new_contents:
/* This class will declare a method inside itself, but will have a
   method declared outside it as well */
class Foo {
  proc internalMeth() {

  }
}

// We expect these two methods to be printed outside of the class indentation
// level
proc Foo.externalMeth1() {

}

/* This method has a comment attached to it */
proc Foo.externalMeth2() {

}

/* Declares one primary and one secondary method... */
record Bar {
  /* A primary method declaration. */
  proc internal() {}
}

/* A secondary method declaration. */
proc Bar.external() {}

subject: Add record with secondary method to chpldoc/ tests.


old_contents:
def foo() { }

def bar() { }

var done: single bool;

def timeout(n: uint) {
  use Time;
  begin { sleep(n); exit(1); }
  begin { done; exit(0); }
}

timeout(30); // exit after 30 seconds or when done is set.

for i in 1..100000 {
  cobegin {
    cobegin { bar(); foo(); }
    cobegin { bar(); foo(); }
    cobegin { bar(); foo(); }
    cobegin { bar(); foo(); }
  }
  if i % 10000 == 0 then
    writeln("iteration ", i, " done.");
}

done = true;

new_contents:
def foo() { }

def bar() { }

var done: single bool;

def timeout(n: uint) {
  use Time;
  begin { sleep(n); writeln("Timeout"); exit(1); }
  begin { done; exit(0); }
}

timeout(30); // exit after 30 seconds or when done is set.

for i in 1..100000 {
  cobegin {
    cobegin { bar(); foo(); }
    cobegin { bar(); foo(); }
    cobegin { bar(); foo(); }
    cobegin { bar(); foo(); }
  }
  if i % 10000 == 0 then
    writeln("iteration ", i, " done.");
}

done = true;

subject: Set up svn:ignore on a directory

message:
Set up svn:ignore on a directory

Set the svn:ignore property on this directory like it is on many other test
directories.

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@13934 3a8e244f-b0f2-452b-bcba-4c88e055c3ca


old_contents:
/*
 * Smallest multiple
 */

config const rangeMax = 20;

const values: [{1..rangeMax}] int;
forall i in 1..rangeMax {
  values[i] = i;
}

proc isMultiple(value: int, numbers: [] int) {
  for num in numbers {
    if value % num != 0 {
      return false;
    }
  }
  return true;
}

// Return least common multiple for list of ints.
proc lcm(numbers: [] int) {
  var maxNum = max reduce numbers,
    value = maxNum;

  while (!isMultiple(value, numbers)) {
    value += maxNum;
  }

  return value;
}

writeln(lcm(values));

new_contents:
/*
 * Smallest multiple
 */

config const rangeMax = 20;

const values: [{1..rangeMax}] int = [i in 1..rangeMax] i;

proc isMultiple(value: int, numbers: [] int) {
  for num in numbers {
    if value % num != 0 {
      return false;
    }
  }
  return true;
}

// Return least common multiple for list of ints.
proc lcm(numbers: [] int) {
  var maxNum = max reduce numbers,
    value = maxNum;

  while (!isMultiple(value, numbers)) {
    value += maxNum;
  }

  return value;
}

writeln(lcm(values));

message:
Update solution 5 to work with new-and-improved constness checking.

Previously it was taking advantage of the lack of constness checking on arrays.

repos: thomasvandoren/project-euler


old_contents:
config const n = 11;
var s0 = "kiss kiss";

var l0: atomic int;
var l1: atomic int;

writeln(s0);
begin ref(s0) {
  l0.waitFor(1);
  s0 = "bang bang";
  l1.write(1);
}

on Locales[numLocales-1] {
  l0.write(1);
  l1.waitFor(1);
  writeln(s0);
}

new_contents:
config const n = 11;
var s0 = "kiss kiss";

var l0: atomic int;
var l1: atomic int;

writeln(s0);
begin with (ref s0) {
  l0.waitFor(1);
  s0 = "bang bang";
  l1.write(1);
}

on Locales[numLocales-1] {
  l0.write(1);
  l1.waitFor(1);
  writeln(s0);
}

subject: Update one last test to the new task intent syntax


old_contents:
/*
 * Highly divisible triangular number
 */

config const minDivisors = 500,
  printNumbers = false;

proc main() {
  for t in triangleNumbers() {

    if printNumbers then
      writef("%di: ", t);

    var count = 0;
    for f in factors(t) {
      count += 1;

      if printNumbers then
        writef("%di, ", f);
    }
    if printNumbers then
      writeln();

    if count > minDivisors {
      writeln(t);
      break;
    }
  }
}

// Yield all the factors of n.
iter factors(n) {
  // Yield 1 and n first, then all intermediate factors.
  yield 1;
  yield n;

  var i = 2;
  while (i < sqrt(n)) {
    if n % i == 0 {
      yield i;
      yield n / i;
    }
    i += 1;
  }

  if i ** 2 == n {
    yield i;
  }
}

// Yield triangle numbers infinitely. Up to caller to break iteration.
iter triangleNumbers() {
  var num = 1,
    triangleNum = num;
  for i in 1..max(int) {
    yield triangleNum;
    num += 1;
    triangleNum += num;
  }
}

new_contents:
/*
 * Highly divisible triangular number
 */

config const minDivisors = 500,
  printNumbers = false;

proc main() {
  for t in triangleNumbers() {

    if printNumbers then
      writef("%n: ", t);

    var count = 0;
    for f in factors(t) {
      count += 1;

      if printNumbers then
        writef("%n, ", f);
    }
    if printNumbers then
      writeln();

    if count > minDivisors {
      writeln(t);
      break;
    }
  }
}

// Yield all the factors of n.
iter factors(n) {
  // Yield 1 and n first, then all intermediate factors.
  yield 1;
  yield n;

  var i = 2;
  while (i < sqrt(n)) {
    if n % i == 0 {
      yield i;
      yield n / i;
    }
    i += 1;
  }

  if i ** 2 == n {
    yield i;
  }
}

// Yield triangle numbers for all integer values. Up to caller to break
// iteration.
iter triangleNumbers() {
  var triangleNum = 1;
  for num in 2..max(int)-1 {
    yield triangleNum;
    triangleNum += num;
  }
}

subject: Update solution 12 to avoid overflow.

message:
Update solution 12 to avoid overflow.

Previously, it had a loop that went up to max(int). This overflows on the very
final check, since the index will be max(int) and then it will add 1 to it. To
avoid the overflow, iterate to max(int)-1.


old_contents:
extern proc return_string_test():string;
extern proc return_string_arg_test(ref string);

writeln("returned string ",return_string_test()); stdout.flush();
var s:string;
on Locales(1) do
  return_string_arg_test(s);
writeln("returned string arg ",s);

new_contents:
extern proc return_string_test():c_string;
extern proc return_string_arg_test(ref c_string);

writeln("returned string ",return_string_test()); stdout.flush();
var s:string;
on Locales(1) do
  return_string_arg_test(s);
writeln("returned string arg ",s);

message:
Change extern prototypes to specify c_string instead of string

[ok'ed by Brad]

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@23791 3a8e244f-b0f2-452b-bcba-4c88e055c3ca


old_contents:
var %(aname)s__defaultRect = pych_to_chpl1D(%(aname)s_pych);
var %(aname)s => _getArray(%(aname)s__defaultRect);

new_contents:
var %(aname)s__defaultRect = pych_to_chpl1D(%(aname)s_pych);
ref %(aname)s = _getArray(%(aname)s__defaultRect);

subject: Use a ref instead of an alias operation

message:
Use a ref instead of an alias operation

Aliases are now deprecated.  The preferred strategy is to use a ref variable.


old_contents:
iter foo(n: int) {
  for i in 1..n do
    yield i;
}

iter foo(param tag: iterKind, n: int) where tag == iterKind.leader {
  cobegin {
    on Locales(0) do yield tuple(0..n-1 by 2);
    on Locales(1) do yield tuple(1..n-1 by 2);
  }
}

iter foo(param tag: iterKind, followThis, n: int) where tag == iterKind.follower {
  for i in followThis(1)+1 do
    yield i;
}

config var n: int = 8;

var A: [1..n] int;

forall i in foo(n) do
  A(i) = here.id * 100 + i;

writeln(A);

use Random;

{
  var B: [1..n] real;

  var rs = new RandomStream(seed=315);

  forall (i, r) in ({1..n}, rs.iterate({1..n})) do
    B(i) = r;

  writeln(B);
}

{
  var B: [1..n] real;

  var rs = new RandomStream(seed=315);

  forall (f, r) in (foo(n), rs.iterate({1..n})) do
    B(f) = r;

  writeln(B);
}

new_contents:
iter foo(n: int) {
  for i in 1..n do
    yield i;
}

iter foo(param tag: iterKind, n: int) where tag == iterKind.leader {
  cobegin {
    on Locales(0) do yield tuple(0..n-1 by 2);
    on Locales(1) do yield tuple(1..n-1 by 2);
  }
}

iter foo(param tag: iterKind, followThis, n: int) where tag == iterKind.follower {
  for i in followThis(1)+1 do
    yield i;
}

config var n: int = 8;

var A: [1..n] int;

forall i in foo(n) do
  A(i) = here.id * 100 + i;

writeln(A);

use Random;

{
  var B: [1..n] real;

  var rs = new RandomStream(seed=315);

  forall (i, r) in zip({1..n}, rs.iterate({1..n})) do
    B(i) = r;

  writeln(B);
}

{
  var B: [1..n] real;

  var rs = new RandomStream(seed=315);

  forall (f, r) in zip(foo(n), rs.iterate({1..n})) do
    B(f) = r;

  writeln(B);
}

subject: Update to new zip() syntax.

message:
Update to new zip() syntax.

This one slipped through the cracks, probably because it is only
tested for gasnet.

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@20700 3a8e244f-b0f2-452b-bcba-4c88e055c3ca


old_contents:
use Time;

config const numIters = 100000;

proc main() {
   begin doSomeWork();
   // while original task exits
   writeln("Original task falling out of main");
}

proc doSomeWork() {
   for i in 1..numIters {
     write("");
     stdout.flush();
   }
   writeln("done working");
}

new_contents:
use Time;

config const numIters = 100000;
var s$: sync bool;

proc main() {
   begin doSomeWork();
   // while original task exits
   writeln("Original task falling out of main");
   s$ = true;
}

proc doSomeWork() {
   s$;
   for i in 1..numIters {
     write("");
     stdout.flush();
   }
   writeln("done working");
}

message:
Fix race condition that was causing valgrind testing non-determinism

Add synchronization to make sure output is printed in the right order
while preserving the intent of the test (main thread continues on
after a begin).

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@20383 3a8e244f-b0f2-452b-bcba-4c88e055c3ca


old_contents:
use Filerator;

for dir in walkdirs("subdir") {
  writeln("dir ", dir, " contains:");
  for file in glob(dir+"/*") do
    writeln("  ", file);
}

new_contents:
use Filerator;

for dir in walkdirs("subdir", sort=true) {
  writeln("dir ", dir, " contains:");
  for file in glob(dir+"/*") do
    writeln("  ", file);
}

subject: Fix nondeterministic output from walkdir() by requesting sorted output


old_contents:
// Calcuate pi using a monte carlo simulation

use Random, Time;

config const n = 10000, seed = 314159;
config const verbose: bool = false;

var count:int;
var pi, startTime, totalTime: real;
var rs = RandomStream(seed);

startTime = getCurrentTime(microseconds);

// Find random points on the complex plane in (0..1+i)
// and count how many are outside the unit circle.
count = + reduce [1..n] abs(rs.getNext()**2 + rs.getNext()**2):int;

// The probability a point is inside the unit circle is pi / 4.
pi = 4 * (n-count):real(64) / n;

// Write out the results
writeln(pi);
totalTime = (getCurrentTime(microseconds) - startTime) / 1000000;
if (verbose) then
  writeln("Calculation took: ", totalTime, " seconds");

new_contents:
// Calcuate pi using a monte carlo simulation

use Random, Time;

config const n = 10000, seed = 314159;
config const verbose: bool = false;

var count:int;
var pi, startTime, totalTime: real;
var rs = RandomStream(seed);

startTime = getCurrentTime(microseconds);

// Find random points on the complex plane in (0..1+i)
// and count how many are outside the unit circle.
count = + reduce for 1..n do abs(rs.getNext()**2 + rs.getNext()**2):int;

// The probability a point is inside the unit circle is pi / 4.
pi = 4 * (n-count):real(64) / n;

// Write out the results
writeln(pi);
totalTime = (getCurrentTime(microseconds) - startTime) / 1000000;
if (verbose) then
  writeln("Calculation took: ", totalTime, " seconds");

message:
Change an incorrect bracket syntax forall expression into a for expression for a
loop that needs to be serial.

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@11785 3a8e244f-b0f2-452b-bcba-4c88e055c3ca


old_contents:
// Test logical AND and OR reductions

param M = 10;

var D: domain(1) = [1..M];
var B: [D] bool;
forall i in D do {
  B(i) = true;
}
writeln( "\nB[D] = ", B);
writeln( "&& reduce B[D] = ", && reduce B);
writeln( "|| reduce B[D] = ", || reduce B);

forall i in D do {
  B(i) = false;
}
writeln( "\nB[D] = ", B);
writeln( "&& reduce B[D] = ", && reduce B);
writeln( "|| reduce B[D] = ", || reduce B);

var toggle: sync bool = false;
forall i in D do {
  var my_toggle = !toggle;
  toggle = my_toggle;
  B(i) = my_toggle;
}
writeln( "\nB[D] = ", B);
writeln( "&& reduce B[D] = ", && reduce B);
writeln( "|| reduce B[D] = ", || reduce B);

new_contents:
// Test logical AND and OR reductions

param M = 10;

var D: domain(1) = [1..M];
var B: [D] bool;
forall i in D do {
  B(i) = true;
}
writeln( "\nB[D] = ", B);
writeln( "&& reduce B[D] = ", && reduce B);
writeln( "|| reduce B[D] = ", || reduce B);

forall i in D do {
  B(i) = false;
}
writeln( "\nB[D] = ", B);
writeln( "&& reduce B[D] = ", && reduce B);
writeln( "|| reduce B[D] = ", || reduce B);

forall i in D do {
  var toggle: bool = i % 2 == 1;
  B(i) = toggle;
}
writeln( "\nB[D] = ", B);
writeln( "&& reduce B[D] = ", && reduce B);
writeln( "|| reduce B[D] = ", || reduce B);

message:
Change the last forall loop in this reduction test to make it deterministic.

Compute the value of a bool independently at each iteration instead of
depending on the value from the previous iteration.

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@16103 3a8e244f-b0f2-452b-bcba-4c88e055c3ca


subject: Add test from commit message

message: Add test from commit message


old_contents:
// A test of the QuickSort function in the Sort module

use Sort;
use Random;

config const size = 4096;

def main() {
  var A: [1..size] int;
  var rands: [1..size] real;
  var randomStream = RandomStream();

  // Fill A with random int values in [0, 99999]
  randomStream.fillRandom(rands);
  [i in 1..size] A(i) = (100000 * rands(i)):int;

  QuickSort(A);

  // Check that A is sorted
  [i in 1..size-1] {
    if A(i) > A(i+1) then
      writeln(A(i), " ", A(i+1));
  }
}

new_contents:
// A test of the QuickSort function in the Sort module

use Sort;
use Random;

config const size = 4096;
config const seed = 27;

def main() {
  var A: [1..size] int;
  var rands: [1..size] real;
  var randomStream = RandomStream(seed);

  // Fill A with random int values in [0, 99999]
  randomStream.fillRandom(rands);
  [i in 1..size] A(i) = (100000 * rands(i)):int;

  QuickSort(A);

  // Check that A is sorted
  [i in 1..size-1] {
    if A(i) > A(i+1) then
      writeln(A(i), " ", A(i+1));
  }
}

message:
Make the seed to the RandomStream class in my QuickSort test be set to
something that causes the "infinite" loop failure instead of the current time.

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@9702 3a8e244f-b0f2-452b-bcba-4c88e055c3ca


old_contents:
//
// Measures both array iteration and array access time
//

use Memory, Time, Types;

config const zipIter = false;
config const memFraction = 100;
config const printPerf = false;

type elemType = uint(8);

const totalMem = here.physicalMemory(unit = MemUnits.Bytes);
const n = (totalMem / numBytes(elemType)) / memFraction;

const space = 1..n;
var data : [space] elemType;
var x : elemType = 2;

var time : Timer;
time.start();
if zipIter {
  forall (i, j) in zip(data, data) with (ref x) do
    x *= i;
} else {
  forall i in data with (ref x) do
    x *= i;
}
time.stop();

if printPerf then writeln("Time: ", time.elapsed());

new_contents:
//
// Measures both array iteration and array access time
//

use Memory, Time, Types;

config const zipIter = false;
config const memFraction = 100;
config const printPerf = false;

type elemType = uint(8);

const totalMem = here.physicalMemory(unit = MemUnits.Bytes);
const target = (totalMem / numBytes(elemType)) / memFraction;
// set a maximum problem size
const n = min(target, 8 * 1e9) : int;

const space = 1..n;
var data : [space] elemType;
var x : elemType = 2;

var time : Timer;
time.start();
if zipIter {
  forall (i, j) in zip(data, data) with (ref x) do
    x *= i;
} else {
  forall i in data with (ref x) do
    x *= i;
}
time.stop();

if printPerf then writeln("Time: ", time.elapsed());

subject: Set a maximum problem size to avoid timeouts


old_contents:
config const n = 100;
config const shift = 2;
config type myType = real;

use Random;

var randlist = new RandomStream(314159265);
var T: [1..n] real;
randlist.fillRandom(T);

proc foo(type myType) {
  var A = (T*(1<<shift):real):myType;
  var x: sync myType = 0:myType;
  forall i in 1..n do
    x += A[i];
  var sum = + reduce A;
  // This check could run into troubles with floating point types
  if x.readXX() != sum then
    writeln("ERROR: sums do not match for ", typeToString(myType),
            " (should be ", sum, ", result is ", x.readXX(), ")");
}

foo(int(32));
foo(int(64));
foo(uint(32));
foo(uint(64));
foo(real(32));
foo(real(64));

new_contents:
config const n = 100;
config type myType = real;

var T: [1..n] real;
[i in 1..n] T[i] = i*1.01;

proc foo(type myType) {
  var A = T:myType;
  var x: sync myType = 0:myType;
  forall i in 1..n do
    x += A[i];
  var sum = + reduce A;
  if x.readXX() != sum then
    writeln("ERROR: sums do not match for ", typeToString(myType),
            " (should be ", sum, ", result is ", x.readXX(), ")");
}

foo(int(32));
foo(int(64));
foo(uint(32));
foo(uint(64));
foo(real(32));
foo(real(64));

message:
Change initialization to avoid numerical instability.

Brad pointed out that I could avoid the numerical instability by using
fixed values.  These aren't fixed, but they're multiples of fixed
values, which seems to do the trick.

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@19933 3a8e244f-b0f2-452b-bcba-4c88e055c3ca


old_contents:
/*
 * Open a file and confirm its FS type is lustre.
 */

use IO;

var fp = open("SKIPIF", iomode.r),
  fileType = fp.fstype();

if fileType == FTYPE_LUSTRE {
  writeln("SUCCESS");
} else {
  writeln("FAILURE");
}

new_contents:
/*
 * Open a file and confirm its FS type is lustre.
 */

use IO;

const fsTypes: [{0..3}] string = [
  "none",
  "hdfs",
  "UNKNOWN", // lustre is LUSTRE_SUPER_MAGIC (whatever that is)
  "curl"
];

var fp = open("SKIPIF", iomode.r),
  fileType = fp.fstype();

if fileType == FTYPE_LUSTRE {
  writeln("SUCCESS");
} else {
  writef("FAILURE: Expected FTYPE_LUSTRE (%n), actual: %s (%n)\n",
         FTYPE_LUSTRE, fsTypes[fileType], fileType);
}

subject: Update error message to be more helpful.


old_contents:
var a: sync int;
var b = 0;

cobegin {
  {
    b = 1;
    while (a < 3) {
      b = 2;
    }
  }
  a = 1;
  a += 1;
  a += 1;
}

if (b==2) then {
  writeln ("b is good");
} else {
  writeln ("b is bad");
}

new_contents:
var a: sync int;
var b = 0;

cobegin {
  {
    b = 1;
    while (a < 3) {
      b = 2;
    }
  }
  {
    a = 1;
    a = 2;
    a = 3;
  }
}

if (b==2) then {
  writeln ("b is good");
} else {
  writeln ("b is bad: ", b);
}

subject: Fix my spin wait -> sync var change

message:
Fix my spin wait -> sync var change

I realized that it had the possibility to deadlock the way I changed it because
+= causes a read and write.

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@13565 3a8e244f-b0f2-452b-bcba-4c88e055c3ca


old_contents:
//
// Measures both array iteration and array access time
//

use Memory, Time, Types;

config const zipIter = false;
config const memFraction = 16;
config const printPerf = false;

type elemType = uint(8);

const totalMem = here.physicalMemory(unit = MemUnits.Bytes);
const n = (totalMem / numBytes(elemType)) / memFraction;

const space = 1..n;
var data : [space] elemType;
var x : elemType = 2;

var time : Timer;
time.start();
if zipIter {
  forall (i, j) in zip(data, data) with (ref x) do
    x *= i;
} else {
  forall i in data with (ref x) do
    x *= i;
}
time.stop();

if printPerf then writeln("Time: ", time.elapsed());

new_contents:
//
// Measures both array iteration and array access time
//

use Memory, Time, Types;

config const zipIter = false;
config const memFraction = 100;
config const printPerf = false;

type elemType = uint(8);

const totalMem = here.physicalMemory(unit = MemUnits.Bytes);
const n = (totalMem / numBytes(elemType)) / memFraction;

const space = 1..n;
var data : [space] elemType;
var x : elemType = 2;

var time : Timer;
time.start();
if zipIter {
  forall (i, j) in zip(data, data) with (ref x) do
    x *= i;
} else {
  forall i in data with (ref x) do
    x *= i;
}
time.stop();

if printPerf then writeln("Time: ", time.elapsed());

subject: Reduce problem size to avoid timeouts on non-performance configurations