Versions Compared

Key

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

...

Code Block
titleuserComputeStep.py
borderStylesolid
class ComputeStep:
  @staticmethod
  def createAwaitsList(tupleContainer, tag ):
    # e.g. tupleContainer.add(itemCollection, tagValue)
    # e.g. operation on item collections: anItemCollection.get(aTag)
    # no dependencies, do nothing
    pass

  @staticmethod
  def compute(tag , outPrimes):
    # e.g. operation on input item collections: anItemCollection.get(aTag)
    # e.g. operation on output item collections: anItemCollection.put(aTag, aValue)
    # e.g. operation on tag collections: aTagCollection.putTag(aTag)
    candidate = int(tag)
    if ComputeStep.isPrime(candidate):
      outPrimes.put(str(candidate), candidate)
    return True

  @staticmethod
  def isPrime(n):
    for k in xrange(3, n, 2):
        if n % k == 0:
           return False
    return True

Please refer to the Partition-String example to see an example of how to implement the createAwaitsList function.

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

Code Block

Running FindPrimesMain
Starting FindPrimesMain...
...
FindPrimesMain execution time: ... ms.
FindPrimesMain ends.
py: processing 100
py: Elapsed time: ... ms
Contents of py:FindPrimes.PrimesItemCollection [size=24]
'11' = 11
'13' = 13
'17' = 17
'19' = 19
'23' = 23
'29' = 29
'3' = 3
'31' = 31
'37' = 37
'41' = 41
'43' = 43
'47' = 47
'5' = 5
'53' = 53
'59' = 59
'61' = 61
'67' = 67
'7' = 7
'71' = 71
'73' = 73
'79' = 79
'83' = 83
'89' = 89
'97' = 97