You are a guest. Restricted access. Read more.
Command disabled: revisions

Programming with SCaVis

SCaVis Java numerical libraries are designed for programming using several languages:

  • Jython - Python language implemented in Java. Probably, this is the most simple and the most powerful approach as it combines the strength of the Python language with most complete and most popular Java. Read the tutorial online or the book
  • Groovy - dynamic language for the Java Virtual Machine (JVM). This language is better integrated with java virtual machine and the scripts run faster than those implemented in Jython. Read the tutorial online.
  • JRuby - another dynamic language, Ruby, which runs inside JVM. This language is also well integrated with JVM and the scripts run faster than those implemented in Jython. Read the JRuby tutorial online.
  • BeanShell - another scripting language which have the full access to Java API, but it is mainly designed to call Java classes without its own API. Read about it here
  • Java - as above to build compiled Java bitecode libraries without interactivity. No need to introduce - this is the backbone of the scripting languages above, but you can still program using it. Read Java tutorial online
  • Matlab or Octave - for analytic calculations (interactive). Octave is a high-level language intended for numerical or analytical computations. It is a Matlab-like numerical programming language. You can find about the syntax of Octave-type macros here.

The structure of the program is shown on this diagram:

As explained in Section running_scripts, one can execute macros/source files using the “run” button: SCaVis recognizes file formats on the fly. Read also online resources in Sect.Jython,BeanShell and Java resources.

Here is an example which benchmarks several arrays implemented in the native Java (ArrayList), Python (list) and SCaVis P0D array. The script below checks the CPU time needed to fill these arrays with Gaussian-distributed random numbers:

Code example

  Download for this example is disabled for non-members
 1: from java.util import *
 2: from jhplot import *
 3: import time
 4:
 5: a=P0D("high-performance")
 6: b=ArrayList()
 7: c=[]
 8: r=Random()
 9:
10: Ntot=3000000 # number of events for testing
11:
12: start = time.clock()
13: for i in range(Ntot):
14:       x=r.nextGaussian()
15:       a.add(x)
16: print ' CPU time for P0D (s) in Jython Loop=',time.clock()-start
17:
18:
19: start = time.clock()
20: a.randomNormal(Ntot, 0, 1)
21: print ' CPU time for P0D (s) native method =',time.clock()-start
22:
23:
24: start = time.clock()
25: for i in range(Ntot):
26:       x=r.nextGaussian()
27:       c.append(x)
28: print ' CPU time for Jython list (s)=',time.clock()-start
29:
30:
31:
32: start = time.clock()
33: for i in range(Ntot):
34:       x=r.nextGaussian()
35:       b.add(x)
36: print ' CPU time for Java ArrayList (s)=',time.clock()-start

A typical result of this benchmark is shown below:

 CPU time for P0D (s) in Jython Loop= 6.992618494
 CPU time for P0D (s) native method = 0.735553826
 CPU time for Jython list (s)= 5.587339718
 CPU time for Java ArrayList (s)= 7.618703669

As you can see, the performance of P0D when using its native method is a factor 10 better.

To speed up your applications, use the native methods of the SCaVis classes when possible

Same code in BeanShell

You can also use the BeanShell as an alternative scripting language. Generally, BeanShell is slower the Jython in loops, but if you call the native methods of high-performance classes (as for P0D in the example above), then the execution speed will be very similar:

import java.util.*;
import jhplot.*;
import time.*;
 
a=new P0D("high-performance");
b=new ArrayList();
r=new Random();
 
Ntot=3000000; //  number of events for testing
 
start= System.currentTimeMillis();
for (i=0; i<Ntot; i++){
      x=r.nextGaussian();
      a.add(x);
      };
 
print("CPU time for P0D (s) in Jython Loop=");
print(0.001*(System.currentTimeMillis()-start));
 
start= System.currentTimeMillis();
a.randomNormal(Ntot, 0, 1);
print("CPU time for P0D (s) native  Loop=");
print(0.001*(System.currentTimeMillis()-start));
 
 
start= System.currentTimeMillis();
for (i=0; i<Ntot; i++){
      x=r.nextGaussian();
      b.add(x);
      };
 
print("CPU time for Java ArrayList Loop=");
print(0.001*(System.currentTimeMillis()-start));

Running the above code in the SCaVis gives:

bsh %
 CPU time for P0D (s) in Jython Loop= 15.093
 CPU time for P0D (s) native  Loop= 0.71
 CPU time for Java ArrayList Loop= 17.435

BeanShell is a factor two slower then Jython in loops, but the performance is very similar to Jython when calling the native Java-implemented methods

You are not full member and have a limited access to this section. One can unlock advanced pages after becoming a full member. You can also request to edit this manual and insert comments.

click here if you want to know more

click here if you want to know more

click here if you want to know more

A complete description of how to use Jython for scientific analysis is described in the book Scientific data analysis using Jython and Java published by Springer Verlag, London, 2010 (by S.V.Chekanov)

Sergei Chekanov 2011/07/02 19:52

Navigation

Print/export