Basic Gridify Prime Numbers example.
This example demonstrates how prime number check it can be grid-enabled using GridGain and Gridify ![]()
Basically it takes all possible number divisors (from 2 up to the number itself but can be optimized of course) and splits them among available nodes on the Grid. Then every node checks whether given number can be divided by at least one of the divisors and if so returns back found divisor.
If all nodes that tested their own divisors set return nothing then this number is a prime one. If at least one node returns divisor then this number is not prime.
Example makes a call of checkPrime(...) method of GridPrimeChecker.java class. Since this method is annotated with Gridify ![]()
![]()
You can find this example at ${GRIDGAIN_HOME}/examples/src folder in package org.gridgain.examples.primenumbers.gridify. Source code is fully Javadoc-ed and you can find the examples' Javadoc at ${GRIDGAIN_HOME}/examples/javadoc folder.
Package:
org.gridgain.examples.primenumbers.gridify
| Class | Description |
|---|---|
| GridifyPrimeExample.java | This is main class in this example. It basically starts grid locally (local node) and executes check of every prime number. If there are grid nodes available this calculation will be gridified to other nodes. |
| GridifyPrimeTask.java | This class represents all the logic necessary for split and aggregate of prime number check. There are two methods in this class responsible for splitting method invocation into multiple sub-calls and aggregating results back from splits. |
Package:
org.gridgain.examples.primenumbers
| GridPrimeChecker.java | Simple prime checker. The implementation of this class iterates through the passed in list of divisors and checks if the value is divisible by any of these divisors. Note that this class checkPrime(long, long, long) method has Gridify |
