Serialized output for test to make it non-deterministic.  I used a config const
and the serial statement.

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

def foo() {
  var k = 2;
  forall j in ([i in 1..2] i + k, 1..2) do
    writeln(j);
}

config const b = true;

serial b do foo();

def main() {
  var k = 2;
  forall j in ([i in 1..2] i + k, 1..2) do
    writeln(j);
}


Added some casts to my problem size printing
routine in order to make it work with both
int and uint problem sizes.

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

use Memory;
use Types;

module HPCCProblemSize {
  def computeProblemSize(type elemType, numArrays, returnPow2 = false,
                         memRatio:int = 4) {
    const totalMem = + reduce physicalMemory(Locale, unit = Bytes),
          memoryTarget = totalMem / memRatio,
          bytesPerIndex = numArrays * numBytes(elemType);

    var numIndices = memoryTarget / bytesPerIndex;

    if (returnPow2) {
      var lgProblemSize = lg(numIndices);
      numIndices = 0x1 << lgProblemSize;  // BLC: exponentiation
      if (numIndices * bytesPerIndex <= memoryTarget) {
        numIndices *= 2;
      }
    }

    const smallestMem = min reduce physicalMemory(Locale, unit = Bytes);
    if ((numIndices * bytesPerIndex)/numLocales > smallestMem) then
      halt("System is too heterogeneous: blocked data won't fit into memory");

    return numIndices;
  }

  def printProblemSize(type elemType, numArrays, problemSize: ?psType) {
    const bytesPerArray = problemSize * numBytes(elemType): psType,
          totalMemInGB = (numArrays * bytesPerArray:float) / (1024**3),
          lgProbSize = lg(problemSize):psType;
    write("Problem size = ", problemSize);
    if (2**lgProbSize == problemSize) {
      write(" (2**", lgProbSize, ")");
    }
    writeln();
    writeln("Bytes per array = ", bytesPerArray);
    writeln("Total memory required (GB) = ", totalMemInGB);
  }
}

use Memory;
use Types;

module HPCCProblemSize {
  def computeProblemSize(type elemType, numArrays, returnPow2 = false,
                         memRatio:int = 4) {
    const totalMem = + reduce physicalMemory(Locale, unit = Bytes),
          memoryTarget = totalMem / memRatio,
          bytesPerIndex = numArrays * numBytes(elemType);

    var numIndices = memoryTarget / bytesPerIndex;

    if (returnPow2) {
      var lgProblemSize = lg(numIndices);
      numIndices = 0x1 << lgProblemSize;  // BLC: exponentiation
      if (numIndices * bytesPerIndex <= memoryTarget) {
        numIndices *= 2;
      }
    }

    const smallestMem = min reduce physicalMemory(Locale, unit = Bytes);
    if ((numIndices * bytesPerIndex)/numLocales > smallestMem) then
      halt("System is too heterogeneous: blocked data won't fit into memory");

    return numIndices;
  }

  def printProblemSize(type elemType, numArrays, problemSize) {
    const bytesPerArray = problemSize * numBytes(elemType),
          totalMemInGB = (numArrays * bytesPerArray):float / (1024**3),
          lgProbSize = lg(problemSize);
    write("Problem size = ", problemSize);
    if (2**lgProbSize == problemSize) {
      write(" (2**", lgProbSize, ")");
    }
    writeln();
    writeln("Bytes per array = ", bytesPerArray);
    writeln("Total memory required (GB) = ", totalMemInGB);
  }
}