Dashboard > GridGain User Guide > Table Of Contents > Examples Gallery > MapReduce with Prime Numbers
MapReduce with Prime Numbers
Added by ghost, last edited by morpheus on Feb 05, 2008  (view change)
Labels: 
(None)


Basic Prime Numbers example.

This example demonstrates how prime number check it can be grid-enabled using GridGain.

Basically it takes all possible number divisors from 2 up to the number itself (this 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.

You can find this example at ${GRIDGAIN_HOME}/examples/src folder in package org.gridgain.examples.primenumbers.api. Source code is fully Javadoc-ed and you can find the examples' Javadoc at ${GRIDGAIN_HOME}/examples/javadoc folder.

Package:
org.gridgain.examples.primenumbers.api

Class Description
GridPrimeExample.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 distributed to other nodes.
GridPrimeTask.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.
GridPrimeChecker.java (GridGain User Guide)
GridPrimeExample.java (GridGain User Guide)
GridPrimeTask.java (GridGain User Guide)

Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators