Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /tests/rtest/tests/sieve/sieve.diderot
ViewVC logotype

View of /tests/rtest/tests/sieve/sieve.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5029 - (download) (annotate)
Tue Jul 11 22:38:23 2017 UTC (22 months, 1 week ago) by jhr
File size: 867 byte(s)
  adding sieve example as regression test
#version 2

/* sieve.diderot
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2017 The University of Chicago
 * All rights reserved.
 *
 * Adapted from https://github.com/Diderot-Language/examples/tree/master/sieve
 */

int NN = 1000;

int nextp = 2; // first prime to find

// Each strand tests one integer, ii, for primality
strand test (int ii) {
   output int out = ii; // Only the primes will actually get saved
   update {
      if (nextp == out) {
         stabilize;    // This adds the value nextp to the saved output
      } else if (out % nextp == 0) {
         die;          // Can't be a prime, discard this value
      }
   }
}

update {
   nextp = min { T.out | T in test.active };
}

/* Start a collection of strands on integers 2 through NN. */
create_collection { test(ii) | ii in 2..NN }

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0