Equation Solution  
    High Performance by Design
Navigation Menu
Home  ⇒  Parallel Computing  ⇒  MTASK  ⇒  Java MTASK  ⇓
Example 1     Example 2    



Java MTASK Example


TASK DISPATCH

        This example illustrates how to dispatch tasking methods. With MTASK, computing streams which can be parallelized are started at a "public void method". The entry method, "public void method", for parallel processing is called tasking method. A tasking method can call private methods and other public methods in the same object, and can refer to other objects. A class can have tasking method as many as necesary. The following example has two tasking methods.

public class parallelExampleA
{
/*
; constructor
*/
   public parallelExampleA( )
  {
      // statements
   }

/*
; tasking method aaa
*/
   puiblic void aaa(float[] arrayA, float[] arrayB)
   {
      //statements
   }

/*
; tasking method bbb
*/
   public void bbb(whateverObject ccc)
   {
      //statements
   }

}

A procedure to dispatch tasking methods is as follows:


import com.equation.mtask.*;

public class caller
{
/*
; use MATSK
*/
   mtask myTasks = new mtask( );

/*
; get my example (defined above)
*/
   parallelExampleA myExample = new parallelExampleA( );

/*
; define array
*/
   //statements to define array

/*
; run method "aaa" in parallel with CPUS tasks
*/
   int[] pid = new int[CPUs-1];

   // create (CPUs-1) tasks
   for (int i = 0; i < (CPUs-1); i++)
   {
      pid[i]=myTasks.dispatch(myExample,
                                              "aaa",
                                              arrayA,
                                              arrayB);
   }

   // run method "aaa" by myself
   myExample.aaa(arrayA,arrayB);

/*
; wait for the completion of tasks
*/
   myTasks.waitForAndTerminateAllTasks( );

   :
   :
}

        This example shows a frame work to dispatch and join tasks. Most parallel applications have a similar procedure to dispatch and join tasks. In a parallel application, tasking methods must be defined, and all the arguments must be passed by reference, i.e. object. Parallel methods usually have parallel lock, parallel event, sequential token and sync calls.