Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Running the command will generate some Scala files. This is how the directory should look:

Code Block

FindPrimes:
  findprimes:
    FindPrimes.cnc
    FindPrimesBase.scala
    FindPrimesGraph.scala
  FindPrimesCncDefinition.scala

In short, these are what the files represent:

...

Code Block
titleUserFindPrimesStep.scala
borderStylesolid

//********************************************************************************
//
// ***** AUTO-GENERATED FILE DO NOT MODIFY!  *****//
//
//********************************************************************************

import edu.rice.cnc.api._
import util.continuations.cps

class UserComputeStep() extends ComputeStep {
  def compute(
               tag: Point,
               outPrimes: OutputCollection[Point, Int]
               ): Unit@cps[Any] = {
    val number: Int = tag(0)
    var factor: Int = 3
    while (number % factor != 0) {
      factor += 2
    }
    if (factor == number) {
      outPrimes.put(tag, number)
    }
  }
}

This step does not rely on input from an Item Collection, instead it uses the tag as the input. Please refer to the Partition String example for a step instance that retrieves inputs from Item Collections.

After providing the Step implementations and a Main class to run and launch the program, the directory should now have the following structure:

Code Block

FindPrimes:
  findprimes:
    FindPrimes.cnc
    FindPrimesBase.scala
    FindPrimesGraph.scala
    FindPrimesMain.scala
    UserFindPrimesStep.scala
  FindPrimesCncDefinition.scala

Now, run the CnC-Scala compiler to compile the Scala files:
cnc_scala_compile

Once the files have been successfully compiled, the application can be run using the CnC-Scala run command:
cnc_scala_run -Dcnc.workers=4 -Dcnc.enableForkJoin=true findprimes.FindPrimesMain 100

Running this program with an input of 100 should produce the following output:

...