Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reduce method has global input and output data types. Its schematic structure is as follows:</p> <pre><code>1 resultValue = grid.reduce( 2 job distribution mode, 3 executable logic function, 4 split function, 5 collect function); </code></pre> <ol> <li>The result value of the task is assigned directly to the return value of the reduce function. Grid is the corresponding grid, where the job is sent to. Multiple grids may be defined and exist in parallel here.</li> <li>The job distribution setting is defined here. The parameter for job distribution offers three options: -GridClosureCallMode.BALANCE – balanced (round robin?) distribution of jobs -GridClosureCallMode.BROADCAST – all nodes process all jobs -GridClosureCallMode.SPREAD – all jobs are randomly distributed</li> <li>The atomic logical function is defined here. This part is called a job; it is send to a node, processed and contains a part of the global result. It has defined input and output data types which are supported. GridGain also supports the distribution of all necessary libraries for this function out of the box. This means the master node is not limited to use libraries, which all nodes have locally available, because all necessary libraries are shipped with the job. This creates of course more data traffic.</li> <li>The input data needs to be distributed to the nodes. Each function is supplied with one of the data sets from the split function. The breakdown of the data is stored in an array list with the corresponding data type. Only low-level data types are supported, due to the implementation results (according to GridGain , also high level data should transferable). To transfer more complex data like PDFs and images, an encapsulation into byte arrays has to be done.</li> <li>The master node uses this function to receive the resulting parts and reassemble them into the final result.</li> </ol> <p>simple example: (does not utilize grid very much as only memory operations and not cpu intensive, so dont expect improvements to single execution)</p> <pre><code>private static int countLettersReducer(String phrase) throws GridException { // final GridLogger log = grid.log(); int letterCount = 0; // Execute Hello World task. try { @SuppressWarnings("unchecked") int letterCnt = grid.reduce(GridClosureCallMode.BALANCE, // input: string // output: integer new GridClosure&lt;String, Integer&gt;() { private static final long serialVersionUID = 1L; // Create executable logic block for a job part @Override public Integer apply(String word) { // Print out a given word, just so we can // see which node is doing what. // System.out.println("&gt;&gt;&gt; Calculating for word: " + word); // Return the length of a given word, i.e. number of // letters. return word.length(); } }, // split tasks for single jobs according to this function // split at linebreaks Arrays.asList(phrase.split("\n")), // Collection of words. // Collect the results from each job of the nodes //input and output is integer new GridReducer&lt;Integer, Integer&gt;() { /** * */ private static final long serialVersionUID = 1L; private int sum; @Override public boolean collect(Integer res) { sum += res; return true; // True means continue collecting until // last result. } // return the collected results @Override public Integer apply() { return sum; } }); letterCount = letterCnt; } catch (Exception e) { } return letterCount; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload