Clean up the threading code in IS by using a coforall instead of begin and sync
var counters. Also, move more work into the coforall so as much as possible can
be divided between multiple cores.

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

use Random;
use Time;

enum classVals {S, W, A, B, C};

config param probClass = S;
config const printTime = false;
config const nThreads = 4;

param seed = 314159265;

const Class: domain(classVals);

const TotalKeys:  [Class] int = ( 2**16, 2**20, 2**23, 2**25, 2**27 ),
      MaxKey:     [Class] int = ( 2**11, 2**16, 2**19, 2**21, 2**23 ),
      TotalIters: [Class] int = ( 10, 10, 10, 10, 10 );

const totalKeys = TotalKeys(probClass);
const maxKey = MaxKey(probClass);
const maxIterations = TotalIters(probClass);

const D: domain(1) = [0..totalKeys);
const E: domain(2) = [0..maxKey-1, 0..nThreads-1];

// The following should be replaced by two enumerated domain arrays of arrays
const S_testIndexArray: [0..4] int = ( 48427,17148,23627,62548,4431 );
const S_testRankArray: [0..4]  int = ( 0,18,346,64917,65463 );
const W_testIndexArray: [0..4] int = ( 357773,934767,875723,898999,404505 );
const W_testRankArray: [0..4]  int = ( 1249,11698,1039987,1043896,1048018 );
const A_testIndexArray: [0..4] int = ( 2112377,662041,5336171,3642833,4250760 );
const A_testRankArray: [0..4]  int = ( 104,17523,123928,8288932,8388264 );
const B_testIndexArray: [0..4] int = ( 41869,812306,5102857,18232239,26860214 );
const B_testRankArray: [0..4]  int = ( 33422937,10244,59149,33135281,99 );
const C_testIndexArray: [0..4] int = ( 44172927,72999161,74326391,129606274,21736814 );
const C_testRankArray: [0..4]  int = ( 61147,882988,266290,133997595,133525895 );

var testIndexArray: [0..4] int;
var testRankArray: [0..4] int;
var partialVerifyVals: [0..4] int;

var keyArray, buffer: [D] int;
var keyBuff1: [E] int;

var passedVerifications = 0;

def main() {
  var time = Timer();
  var randomStream = RandomStream(seed);
  var tempreals: [1..4] real;
  var max = maxKey / 4;

  setupPartialVerify();

  writeln(" NAS Parallel Benchmarks (Chapel) - IS Benchmark\n");
  writeln(" Size:  ", totalKeys, "  (class ", probClass, ")");
  writeln(" Iterations:   ", maxIterations, "\n");

  // Generate Keys
  for i in D {
    randomStream.fillRandom(tempreals);
    keyArray(i) = (max * (+ reduce tempreals)):int;
  }

  // Do one iteration for free (i.e., untimed) to guarantee initialization of
  // all data and code pages and respective tables
  rank(1);

  if (probClass != S) then writeln("   iteration");

  time.start();
  for i in 1..maxIterations {
    if (probClass != S) then writeln("        ", i);
    rank(i);
  }
  time.stop();
  fullVerify();

  writeln("\n\n IS Benchmark Completed");
  writeln(" Class           = ", probClass);
  writeln(" Size            = ", totalKeys);
  writeln(" Iterations      = ", maxIterations);
  if printTime {
    writeln(" Time in seconds = ", time.elapsed(seconds));
    writeln(" Mop/s total     = ",
            (maxIterations*totalKeys)/time.elapsed(seconds)/1000000);
  }
  if (passedVerifications == (maxIterations+1) * 5 + 1) then
    writeln(" Verification    = SUCCESSFUL");
  else
    writeln(" Verification    = FAILED ", passedVerifications);
}

def setupPartialVerify() {
  // Would like to use an array over an enumerated domain of arrays instead
  select probClass {
    when S do {
      testIndexArray = S_testIndexArray;
      testRankArray  = S_testRankArray;
    }
    when W do {
      testIndexArray = W_testIndexArray;
      testRankArray  = W_testRankArray;
    }
    when A do {
      testIndexArray = A_testIndexArray;
      testRankArray  = A_testRankArray;
    }
    when B do {
      testIndexArray = B_testIndexArray;
      testRankArray  = B_testRankArray;
    }
    when C do {
      testIndexArray = C_testIndexArray;
      testRankArray  = C_testRankArray;
    }
  }
}

def rank(iteration: int) {
  const blkSize = totalKeys / nThreads;

  keyArray(iteration) = iteration;
  keyArray(iteration+maxIterations) = maxKey - iteration;

  partialVerifyVals = keyArray(testIndexArray);

  coforall thread in 0..nThreads-1 {
    const low = thread * blkSize;
    const high = if thread == nThreads-1 then D.high else (thread+1)*blkSize-1;
    keyBuff1(0..maxKey-1, thread) = 0;
    keyBuff1(keyArray(low..high), thread) += 1;
    keyBuff1(0..maxKey-1, thread) = + scan keyBuff1(0..maxKey-1, thread);
  }
  partialVerification(iteration);
}

def partialVerification(iteration: int) {
  for i in 0..4 {
    var k = partialVerifyVals(i);
    var val = + reduce keyBuff1(k-1, 0..nThreads-1);
    select probClass {
      when S do {
        if (i <= 2) {
          if (val != testRankArray(i)+iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        } else {
          if (val != testRankArray(i)-iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        }
      }
      when W do {
        if (i < 2) {
          if (val != testRankArray(i) + (iteration-2)) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        } else {
          if (val != testRankArray(i) - iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        }
      }
      when A do {
        if (i <= 2) {
          if (val != testRankArray(i) + (iteration-1)) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        } else {
          if (val != testRankArray(i) - (iteration-1)) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        }
      }
      when B do {
        if (i == 1 || i == 2 || i == 4) {
          if (val != testRankArray(i) + iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        } else {
          if (val != testRankArray(i) - iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        }
      }
      when C do {
        if (i <= 2) {
          if (val != testRankArray(i) + iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        } else {
          if (val != testRankArray(i) - iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        }
      }
    }
  }
}

def fullVerify() {
  var failures = 0;
  for i in 0..maxKey-1 do
    keyBuff1(i, 0) = + reduce keyBuff1(i, 0..nThreads-1);
  buffer = keyArray;
  [i in D] {
    atomic {
      keyBuff1(buffer(i), 0) -= 1;
      keyArray(keyBuff1(buffer(i), 0)) = buffer(i);
    }
  }

  [i in 0..D.numIndices-2]
    if (keyArray(i) > keyArray(i+1)) then failures += 1;

  if (failures != 0) then
    halt("Full verification: number of keys out of sort ", failures);
  else
    passedVerifications += 1;
}

use Random;
use Time;

enum classVals {S, W, A, B, C};

config param probClass = S;
config const printTime = false;
config const nThreads = 4;

param seed = 314159265;

const Class: domain(classVals);

const TotalKeys:  [Class] int = ( 2**16, 2**20, 2**23, 2**25, 2**27 ),
      MaxKey:     [Class] int = ( 2**11, 2**16, 2**19, 2**21, 2**23 ),
      TotalIters: [Class] int = ( 10, 10, 10, 10, 10 );

const totalKeys = TotalKeys(probClass);
const maxKey = MaxKey(probClass);
const maxIterations = TotalIters(probClass);

const D: domain(1) = [0..totalKeys);
const E: domain(2) = [0..maxKey-1, 0..nThreads-1];

// The following should be replaced by two enumerated domain arrays of arrays
const S_testIndexArray: [0..4] int = ( 48427,17148,23627,62548,4431 );
const S_testRankArray: [0..4]  int = ( 0,18,346,64917,65463 );
const W_testIndexArray: [0..4] int = ( 357773,934767,875723,898999,404505 );
const W_testRankArray: [0..4]  int = ( 1249,11698,1039987,1043896,1048018 );
const A_testIndexArray: [0..4] int = ( 2112377,662041,5336171,3642833,4250760 );
const A_testRankArray: [0..4]  int = ( 104,17523,123928,8288932,8388264 );
const B_testIndexArray: [0..4] int = ( 41869,812306,5102857,18232239,26860214 );
const B_testRankArray: [0..4]  int = ( 33422937,10244,59149,33135281,99 );
const C_testIndexArray: [0..4] int = ( 44172927,72999161,74326391,129606274,21736814 );
const C_testRankArray: [0..4]  int = ( 61147,882988,266290,133997595,133525895 );

var testIndexArray: [0..4] int;
var testRankArray: [0..4] int;
var partialVerifyVals: [0..4] int;

var keyArray, buffer: [D] int;
var keyBuff1: [E] int;

var passedVerifications = 0;

def main() {
  var time = Timer();
  var randomStream = RandomStream(seed);
  var tempreals: [1..4] real;
  var max = maxKey / 4;

  setupPartialVerify();

  writeln(" NAS Parallel Benchmarks (Chapel) - IS Benchmark\n");
  writeln(" Size:  ", totalKeys, "  (class ", probClass, ")");
  writeln(" Iterations:   ", maxIterations, "\n");

  // Generate Keys
  for i in D {
    randomStream.fillRandom(tempreals);
    keyArray(i) = (max * (+ reduce tempreals)):int;
  }

  // Do one iteration for free (i.e., untimed) to guarantee initialization of
  // all data and code pages and respective tables
  rank(1);

  if (probClass != S) then writeln("   iteration");

  time.start();
  for i in 1..maxIterations {
    if (probClass != S) then writeln("        ", i);
    rank(i);
  }
  time.stop();
  fullVerify();

  writeln("\n\n IS Benchmark Completed");
  writeln(" Class           = ", probClass);
  writeln(" Size            = ", totalKeys);
  writeln(" Iterations      = ", maxIterations);
  if printTime {
    writeln(" Time in seconds = ", time.elapsed(seconds));
    writeln(" Mop/s total     = ",
            (maxIterations*totalKeys)/time.elapsed(seconds)/1000000);
  }
  if (passedVerifications == (maxIterations+1) * 5 + 1) then
    writeln(" Verification    = SUCCESSFUL");
  else
    writeln(" Verification    = FAILED ", passedVerifications);
}

def setupPartialVerify() {
  // Would like to use an array over an enumerated domain of arrays instead
  select probClass {
    when S do {
      testIndexArray = S_testIndexArray;
      testRankArray  = S_testRankArray;
    }
    when W do {
      testIndexArray = W_testIndexArray;
      testRankArray  = W_testRankArray;
    }
    when A do {
      testIndexArray = A_testIndexArray;
      testRankArray  = A_testRankArray;
    }
    when B do {
      testIndexArray = B_testIndexArray;
      testRankArray  = B_testRankArray;
    }
    when C do {
      testIndexArray = C_testIndexArray;
      testRankArray  = C_testRankArray;
    }
  }
}

def rank(iteration: int) {
  var done: single bool;
  var blkSize = totalKeys / nThreads;
  var threadCnt: sync int = nThreads;

  keyArray(iteration) = iteration;
  keyArray(iteration+maxIterations) = maxKey - iteration;

  partialVerifyVals = keyArray(testIndexArray);
  keyBuff1 = 0;

  for thread in 0..nThreads-1 {
    var low = thread * blkSize;
    var high = if thread == nThreads-1 then D.high else (thread+1)*blkSize - 1;
    var DOM: domain(1) = [low..high];
    begin {
      keyBuff1([i in DOM] keyArray(i), thread) += 1;
      var threadCntL = threadCnt;
      threadCntL -= 1;
      threadCnt = threadCntL;
      if threadCntL == 0 then done = true;
    }
  }
  if done {
    var slice: domain(2) = [0..maxKey-1, 0..0];
    if nThreads > 1 then
      [i in 0..maxKey-1] keyBuff1(i, 0) = + reduce keyBuff1(i, [0..nThreads-1]);

    keyBuff1(slice) = + scan keyBuff1(slice);
    partialVerification(iteration);
  }
}

def partialVerification(iteration: int) {
  for i in 0..4 {
    var k = partialVerifyVals(i);
    select probClass {
      when S do {
        if (i <= 2) {
          if (keyBuff1(k-1, 0) != testRankArray(i)+iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        } else {
          if (keyBuff1(k-1, 0) != testRankArray(i)-iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        }
      }
      when W do {
        if (i < 2) {
          if (keyBuff1(k-1, 0) != testRankArray(i) + (iteration-2)) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        } else {
          if (keyBuff1(k-1, 0) != testRankArray(i) - iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        }
      }
      when A do {
        if (i <= 2) {
          if (keyBuff1(k-1, 0) != testRankArray(i) + (iteration-1)) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        } else {
          if (keyBuff1(k-1, 0) != testRankArray(i) - (iteration-1)) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        }
      }
      when B do {
        if (i == 1 || i == 2 || i == 4) {
          if (keyBuff1(k-1, 0) != testRankArray(i) + iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        } else {
          if (keyBuff1(k-1, 0) != testRankArray(i) - iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        }
      }
      when C do {
        if (i <= 2) {
          if (keyBuff1(k-1, 0) != testRankArray(i) + iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        } else {
          if (keyBuff1(k-1, 0) != testRankArray(i) - iteration) {
            writeln("Failed partial verification: iteration ",
                 iteration, ", test key ", i);
          } else {
            passedVerifications += 1;
          }
        }
      }
    }
  }
}

def fullVerify() {
  var failures = 0;
  buffer = keyArray;
  [i in D] {
    atomic {
      keyBuff1(buffer(i), 0) -= 1;
      keyArray(keyBuff1(buffer(i), 0)) = buffer(i);
    }
  }

  [i in 0..D.numIndices-2]
    if (keyArray(i) > keyArray(i+1)) then failures += 1;

  if (failures != 0) then
    halt("Full verification: number of keys out of sort ", failures);
  else
    passedVerifications += 1;
}


dont use indexer

dont use indexer

use Logging, Memory, LibEv, IO, Indexer, Search, Partitions, Time;

// TODO: port to pure chapel
extern proc initialize_socket(port: c_int): c_int;

// trampolines
extern var c_accept_cb: opaque;

extern proc send(sockfd:c_int, buffer: c_string, len: size_t, flags: c_int);

config var port: c_int = 3033;

// TODO: we need to know which client context this is so that we can maintain parsing context
//       is the fd enough?
export proc handle_received_data(fd: c_int, buffer: c_string, read: size_t, buffer_size: size_t) {
  // writeln("from chpl: " + buffer);
  // accumulate string buffer
  var word = buffer;
  var trimmedWord: string = "";
  writeln("word: ", word);
  for i in 1..word.length {
  	var ch = word.substring(i);
  	if (ch != "\r" && ch != "\n") {
	  	writeln("ch: ", word.substring(i));
	  	trimmedWord += word.substring(i);
  	}
  }
//  writeln("trimmedWord: ", trimmedWord);
	if (trimmedWord == "dump") {
		dumpPartition(partitionForWord("dog"));
	} else {
		writeln("<adding>");
	  indexWord(trimmedWord, 1);
		dumpPostingTableForWord(trimmedWord);
		writeln("</adding>");
	}
  send(fd, buffer, read, 0);
}

proc initIndex() {
	writeln("This program is running on ", numLocales, " locales");
	writeln("It began running on locale #", here.id);
	writeln();

  initPartitions();
  initIndices();

  // initIndexer();

 //  writeln("adding 3 entries");
	// indexWord("dog", 1);
	// indexWord("cat", 2);
	// indexWord("cat", 3);

 //  writeln("dumping partition holding word: dog");
	// dumpPartition(partitionForWord("dog"));

 //  writeln("dumping posting table for word: cat");
	// dumpPostingTableForWord("cat");
  var t: Timer;
  t.start();

  var infile = open("words.txt", iomode.r);
  var reader = infile.reader();
  var word: string;
  var docId: DocId = 1;
  while (reader.readln(word)) {
//    enqueueIndexRequest(word, docId);
    indexWord(word, docId);
    docId = (docId + 1) % 1000 + 1; // fake different docs
  }

//  waitForIndexer();
  t.stop();
  timing("indexing complete in ",t.elapsed(TimeUnits.microseconds), " microseconds");

  //dumpPostingTableForWord("the");

  // TODO: build execution Tree w/ conj / disj. (operator) nodes
  // test basic boolean operators
  // writeln("conjunction");
  // t.start();
  // var conj = conjunction(["the", "dog"]);
  // t.stop();
  // timing("conjunction complete in ",t.elapsed(TimeUnits.microseconds), " microseconds");
  // writeln(conj);

  // writeln("disjunction");
  // t.start();
  // var disj = disjunction(["the", "dog"]);
  // t.stop();
  // timing("disjunction complete in ",t.elapsed(TimeUnits.microseconds), " microseconds");
  // writeln(disj);
}

proc conjunction(words: [] string): domain(DocId) {
  writeln("finding conjunction of: ", words);
  var doms: [1..words.size] domain(DocId);

  for j in 1..words.size {
    var word = words[j];
    var entry = entryForWord(word);
    if (entry != nil) {
      on entry {
        for docId in documentIdsForEntry(entry) {
          doms[j] += docId;
        }
      }
    }
  }

  writeln("applying intersection");

  for j in 2..words.size {
    doms[1] = doms[1] & doms[j];
  }

  return doms[1];
}

proc disjunction(words: [] string): domain(DocId) {
  writeln("finding disjunction of: ", words);
  var doms: [1..words.size] domain(DocId);

  for j in 1..words.size {
    var word = words[j];
    var entry = entryForWord(word);
    if (entry != nil) {
      on entry {
        for docId in documentIdsForEntry(entry) {
          doms[j] += docId;
        }
      }
    }
  }

  writeln("applying disjunction");

  for j in 2..words.size {
    doms[1] = doms[1] | doms[j];
  }

  return doms[1];
}

proc writeLocInfo(loc: locale) {
  on loc {
    writeln("locale #", here.id, "...");
    writeln("  ...is named: ", here.name);
    writeln("  ...has ", here.numCores, " processor cores");
    writeln("  ...has ", here.physicalMemory(unit=MemUnits.GB, retType=real), " GB of memory");
    writeln("  ...has ", here.maxTaskPar, " maximum parallelism");
  }
}

proc main() {

	// writeln("creating socket...");
	// var sd: ev_fd = initialize_socket(port);
	// writeln("socket id = ", sd);
	// if (sd == -1) {
	// 	writeln("socket error");
	// 	return -1;
	// }

  writeln("initializing index");
  initIndex();

	// writeln("initializing event loop...");

 //  // port c_accept_cb, c_read_cb
	// var w_accept: ev_io = new ev_io();
	// ev_io_init(w_accept, c_accept_cb, sd, EV_READ);
	// ev_io_start(EV_DEFAULT, w_accept);

	// while (1) {
	// 	ev_loop_fn(EV_DEFAULT, 0);
	// }
}

use Logging, Memory, LibEv, IO, Indexer, Search, Partitions, Time;

// TODO: port to pure chapel
extern proc initialize_socket(port: c_int): c_int;

// trampolines
extern var c_accept_cb: opaque;

extern proc send(sockfd:c_int, buffer: c_string, len: size_t, flags: c_int);

config var port: c_int = 3033;

// TODO: we need to know which client context this is so that we can maintain parsing context
//       is the fd enough?
export proc handle_received_data(fd: c_int, buffer: c_string, read: size_t, buffer_size: size_t) {
  // writeln("from chpl: " + buffer);
  // accumulate string buffer
  var word = buffer;
  var trimmedWord: string = "";
  writeln("word: ", word);
  for i in 1..word.length {
  	var ch = word.substring(i);
  	if (ch != "\r" && ch != "\n") {
	  	writeln("ch: ", word.substring(i));
	  	trimmedWord += word.substring(i);
  	}
  }
//  writeln("trimmedWord: ", trimmedWord);
	if (trimmedWord == "dump") {
		dumpPartition(partitionForWord("dog"));
	} else {
		writeln("<adding>");
	  indexWord(trimmedWord, 1);
		dumpPostingTableForWord(trimmedWord);
		writeln("</adding>");
	}
  send(fd, buffer, read, 0);
}

proc initIndex() {
	writeln("This program is running on ", numLocales, " locales");
	writeln("It began running on locale #", here.id);
	writeln();

  initPartitions();
  initIndices();

  initIndexer();

 //  writeln("adding 3 entries");
	// indexWord("dog", 1);
	// indexWord("cat", 2);
	// indexWord("cat", 3);

 //  writeln("dumping partition holding word: dog");
	// dumpPartition(partitionForWord("dog"));

 //  writeln("dumping posting table for word: cat");
	// dumpPostingTableForWord("cat");
  var t: Timer;
  t.start();

  var infile = open("words.txt", iomode.r);
  var reader = infile.reader();
  var word: string;
  var docId: DocId = 1;
  while (reader.readln(word)) {
    enqueueIndexRequest(word, docId);
    docId = (docId + 1) % 1000 + 1; // fake different docs
  }

  waitForIndexer();
  t.stop();
  timing("indexing complete in ",t.elapsed(TimeUnits.microseconds), " microseconds");

  //dumpPostingTableForWord("the");

  // TODO: build execution Tree w/ conj / disj. (operator) nodes
  // test basic boolean operators
  writeln("conjunction");
  var conj = conjunction(["the", "dog"]);
  writeln(conj);

  writeln("disjunction");
  var disj = disjunction(["the", "dog"]);
  writeln(disj);
}

proc conjunction(words: [] string): domain(DocId) {
  writeln("finding conjunction of: ", words);
  var doms: [1..words.size] domain(DocId);

  for j in 1..words.size {
    var word = words[j];
    var entry = entryForWord(word);
    if (entry != nil) {
      on entry {
        for docId in documentIdsForEntry(entry) {
          doms[j] += docId;
        }
      }
    }
  }

  writeln("applying intersection");

  for j in 2..words.size {
    doms[1] = doms[1] & doms[j];
  }

  return doms[1];
}

proc disjunction(words: [] string): domain(DocId) {
  writeln("finding disjunction of: ", words);
  var doms: [1..words.size] domain(DocId);

  for j in 1..words.size {
    var word = words[j];
    var entry = entryForWord(word);
    if (entry != nil) {
      on entry {
        for docId in documentIdsForEntry(entry) {
          doms[j] += docId;
        }
      }
    }
  }

  writeln("applying disjunction");

  for j in 2..words.size {
    doms[1] = doms[1] | doms[j];
  }

  return doms[1];
}

proc writeLocInfo(loc: locale) {
  on loc {
    writeln("locale #", here.id, "...");
    writeln("  ...is named: ", here.name);
    writeln("  ...has ", here.numCores, " processor cores");
    writeln("  ...has ", here.physicalMemory(unit=MemUnits.GB, retType=real), " GB of memory");
    writeln("  ...has ", here.maxTaskPar, " maximum parallelism");
  }
}

proc main() {

	// writeln("creating socket...");
	// var sd: ev_fd = initialize_socket(port);
	// writeln("socket id = ", sd);
	// if (sd == -1) {
	// 	writeln("socket error");
	// 	return -1;
	// }

  writeln("initializing index");
  initIndex();

	// writeln("initializing event loop...");

 //  // port c_accept_cb, c_read_cb
	// var w_accept: ev_io = new ev_io();
	// ev_io_init(w_accept, c_accept_cb, sd, EV_READ);
	// ev_io_start(EV_DEFAULT, w_accept);

	// while (1) {
	// 	ev_loop_fn(EV_DEFAULT, 0);
	// }
}


Oops! Forgot to remove my test code.

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

class C {
  param i : uint;
  def initialize() {
    writeln("hello from id ", i, "!");
  }
}

def f(param i : uint) {
  writeln("hello from id ", i, "!");
}

def main() {
  var a = new C(0 : uint); // this works
  var b = new C(1);        // this doesn't
  f(2); // this also works
}

class C {
  param i : uint;
  def initialize() {
    writeln("hello from id ", i, "!");
  }
}

def f(param i : uint) {
  writeln("hello from id ", i, "!");
}

def main() {
  var a = new C(0 : uint); // this works
  var b = new C(1:uint);        // this doesn't
  f(2); // this also works
}