Docstoc

Parallel programming in java

Document Sample
Parallel programming in java Powered By Docstoc
					Parallel programming with java
Benefits
   Portability

   Ease of software engineering

   Object oriented programming
Single vs. Multiple java VM
Java Virtual Machine (VM) is the program
  that interpret java bytecodes .
One fundamental characteristic of java-based
  parallel system is the distinction between
  single VM environment and multiple VM
  environment.
Single vs. Multiple java VM(con)
   Single java VM running a single multi-thread java
    application with java threads distributed across the
    processors in the system.
   A multi-VM provides multiple java VMs, each
    running a discrete java application with some form
    of inter-VM communication facility allowing
    interaction between the applications running on
    different VMs.
Multi-VM programming Models
A multi-VM environment requires some
  mechanism for inter-VM communicaton.
  the three obvious approaches are:
 To use or adopt a suitable existing Java API

  The only current official Java API is
  Java RMI (Remote Method Invocation)
Multi-VM programming Models
 To adopt an existing, widely-used, non-java
  native inter-processor communication
  library and provide a java interface to it .
  example of this are java interface to MPI
  (mpiJava)
 To extend the java programming language
  to add intrinsic parallelism features. an
  example of this is JavaParty
JOMP
   JOMP
       An OpenMP-like interface for Java
       a research project developed at EPCC
       freely available
           http://www.epcc.ed.ac.uk/research/jomp/

       fully portable
   JOMP API
       Based heavily on the C/C++ OpenMP standard
       Directives embedded as comments (as in Fortran)
       //omp <directive> <clauses>
       Library functions are class methods of an OMP class
JOMP Directives
   Critical
   Parallel
   For
   Sections
   Barrier
   Single
   Master
Critical directive
//omp critical [name]
  <block>
After compile with JOMP compiler
Jomp.runtime.OMP.startCritical(“name”)
  <block>
Jomp.runtime.OMP.stopCritical(“name”)
Parallel directive
//omp parallel shared(a,n) private(myid,i)
//omp reduction(+:b)
{
  myid=OMP.getThreadNum();
  for (i=0; i<n; i++){
      b+=a[myid][i];
}
For directive
//omp parallel shared(a,b)
{
//omp for
  for (i=1 ; i<n ;i++){
    b[i]=(a[i]+a[i-1])*0.5;
}
Sections and section directives
//omp parallel shared(a,b,c)
{
//omp sections
  {
//omp sections
   a.init()
Barrier directive
//omp barrier

Jomp.runtime.doBarrier()

JOMP used fast tournament barrier
Single directive
Single directive is used to denote a piece of
  code which must be executed exactly once
  by some member of thread team.
//omp single
<code block>
Master directive
Single directive is used to denote a piece of
  code which is to be executed only by master
  thread .

 //omp master
 <code block>
Parallel hello world
import jomp.runtime.*
Public class Hello{
  public static void main(String argv[]){
  int myid;
 //omp parallel private(myid)
  {
   myid=OMP.getThreadNum();
   system.out.println(“Hello from ”+myid);
  }
 }
}
Scope of variable
   Private
   Shared
   Reduction
   Firstprivate
   Lastprivate
Nested parallelism
Having parallel section in parallel section

setNested()

getNested()

Already not suported.
   java -Djomp.threads=8 MyProg

   Disadvantages
       Still only a research project
       Not yet a defined standard

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:5
posted:10/14/2011
language:English
pages:20