Chapter 43. Interface with Scilab

43.1. Presentation

Scilab is a scientific software for numerical computations. Developped since 1990 by researchers from INRIA and ENPC, it is now maintained and developed by Scilab Consortium since its creation in May 2003. Scilab includes hundreds of mathematical functions with the possibility to add interactively programs from various languages (C, Fortran...). It has sophisticated data structures (including lists, polynomials, rational functions, linear systems...), an interpreter and a high level programming language. Scilab works on most Unix systems (including GNU/Linux) and Windows (9X/2000/XP).

The goal of the ProActive Interface is to equip Scilab with a generic interface to Grid computing. This extension has to allow the deployment of Scilab instances on several nodes of the grid (and to use these instances like computing engines) and the submital of Scilab tasks over the grid. These Scilab engines are monitored by a central ProActive API. A natural condition is to deploy an application (based on this interface) strictly on hosts where the Scilab software is intsalled. To install Scilab and find some documentation about it on the scilab website. This ProActive interface supports the release 4.0 and manipulates the following types: Double, String, Double Matrix, String Matrix.

43.2. Scilab Interface Architecture

The interface architecture is based on the Master-Slaves model. In this communication model, the master entity monitors the slaves entities. In our case:

  • The role of the master is to deploy the topology of scilab instances (slaves) and to distribute tasks (between the different engines);

  • The role of the slave is to perform the submitted tasks (by the master).

There are four classes which are intented for the user:

The Class ScilabService implememts all functionnalities to deploy engines, to distribute tasks, and to retrieve results (of computed tasks).

  • The depoyment is made thank to a ProActive descriptor. This deployment descriptor describes the different nodes of the grid taking part at the computation. One of particularities of this descriptor is the declaration of specific scilab environment variables for each node. The deployment is achieved by a call of the method "deployEngine". This method takes in parameters the VirtualNode id, the descriptor path, and the number of engines to create.

  • The distribution of a Scilab task is made thanks to the call of the method "sendTask". After the call, the task is set in pending queue. This queue is managed like a FIFO with priority. The task is in head of the queue is sent when a engine is available.

  • After the compution of a task, the scilab engine returns the result. To retrieve this result, it is necessary to listen the event "SciEventTask" thank to the method "addEnventListenerTask".

  • This class offers also the possibilities to cancel a pending task, to kill a running task , and to restart a engine.

The Class SciTaskInfo contains all informations about a Scilab task. Among these informations, there are:

  • The state of the tasks:

    • WAIT: The task is in the pending queue

    • RUN: The task is computing by a scilab engine

    • SUCCES: The computation of the task is terminated with success

    • ABORT: The computation of the task was avorted

    • KILL: The task was killed by the user during the computation

    • CANCEL: The Task was cancelled by the user before its computation

  • The global and execution time

  • The priority of the task (LOW, NORMAL, HIGH)

  • The task itself

  • The result of the assiciated task ( It is available when the state is ABORT or SUCCESS)

The class SciTask describes a scilab task. It defines In and Out data, the job and the job initialization. A job is a scilab script (*.sce), it contains all instructions executed by a remote engine. In data and the job initialization allow to customize the execution and Out data define the values to return after the execution.

The class SciResult describes a scilab result. A result is the list of return values (defining in the task).

The following example Example 43.1, “Example: Interface Scilab” presents how to compute a basic task and to display the result. In our case the task initializes the variable "n" and increments it. The next example shows a possibly deployment descriptor Example 43.2, “Descriptor deployment”.

public class SciTest {

	SciTask task;
	ScilabService scilab;
	
	public void  displayResult(SciTaskInfo scitaskInfo){
		// scilab result
		SciResult sciResult = scitaskInfo.getSciResult();
		// list of retrun values
		ArrayList listResult = sciResult.getList();
		
		for (int i = 0; i < listResult.size(); i++) {
			SciData result = (SciData) listResult.get(i);
				System.out.println(result.toString());
		}
		scilab.exit();
	}
	
	public SciTest(String idVN, String pathVN) throws Exception{
		// a new scilab task 
		SciTask task = new SciTask("id"); 
		task.setJobInit("n = 10;");
		task.addDataOut(new SciData("n"));
		task.setJob("n = n+1;");
		
		//a new scilab service
		ScilabService scilab = new ScilabService();
		
		//add task event listener
		scilab.addEventListenerTask( new SciEventListener(){
			public void actionPerformed(SciEvent evt){
				SciTaskInfo sciTaskInfo = (SciTaskInfo) evt.getSource();
				
				if(sciTaskInfo.getState() == SciTaskInfo.SUCCESS){
					 displayResult(sciTaskInfo);
					return;
				}
			}
		});
		
		// deploy engine
		scilab.deployEngine( idVN, pathVN, new String[]{"Scilab"});
		// send task
		scilab.sendTask(task);
		
	}
	
	public static void main(String[] args) throws Exception {
		new SciTest(args[0], args[1]);
	}
}

Example 43.1. Example: Interface Scilab

<?xml version="1.0" encoding="UTF-8"?>
<ProActiveDescriptor xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"http://www-sop.inria.fr/oasis/proactive/schema/3.2/DescriptorSchema.xsd">
  <variables>
    <descriptorVariable name="PROACTIVE_HOME" value="****"/> 
    <descriptorVariable name="REMOTE_HOME" value="****"/>
    <descriptorVariable name="SCILAB_HOME" value="****"/>
  </variables>
  <componentDefinition>
    <virtualNodesDefinition>
      <virtualNode name="ScilabVN" property="multiple"/>
    </virtualNodesDefinition>
  </componentDefinition>
  <deployment>
    <mapping>
      <map virtualNode="ScilabVN">
        <jvmSet>
          <vmName value="Jvm0"/> 
          <vmName value="Jvm1"/>
          <vmName value="Jvm2"/>
          <vmName value="Jvm3"/>   
        </jvmSet>
      </map>
    </mapping>
    <jvms>
      </jvm>
      <jvm name="Jvm1">
        <creation>
          <processReference refid="rsh_predadab"/> 
        </creation>
      </jvm>
      <jvm name="Jvm2">
        <creation>
          <processReference refid="rsh_trinidad"/>
        </creation>
      </jvm>
      <jvm name="Jvm3">
        <creation>
           <processReference refid="rsh_apple"/>                                         
        </creation>
      </jvm>
    </jvms>
  </deployment>
  <infrastructure>
    <processes>
      <processDefinition id="localJVM">
        <jvmProcess class="org.objectweb.proactive.core.process.JVMNodeProcess">
          <classpath>
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/ProActive.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/asm.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/log4j.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/components/fractal.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/xercesImpl.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/bouncycastle.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/jsch.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/lib/javassist.jar" />
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/classes" />
            <absolutePath value="${REMOTE_HOME}/${SCILAB_HOME}/bin/javasci.jar" />
          </classpath>
          <javaPath>
            <absolutePath value="****" />
          </javaPath>
          <policyFile>
            <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/scripts/proactive.java.policy"
 />
          </policyFile>
          <log4jpropertiesFile>
             <absolutePath value="${REMOTE_HOME}/${PROACTIVE_HOME}/scripts/proactive-log4j" />
        </log4jpropertiesFile>                          
      </processDefinition>
      <processDefinition id="rsh_predadab">
        <rshProcess class="org.objectweb.proactive.core.process.rsh.RSHProcess" hostname=
"predadab">
          <environment>
            <variable name="SCIDIR" value="${REMOTE_HOME}/${SCILAB_HOME}"/>
            <variable name="SCI" value="${REMOTE_HOME}/${SCILAB_HOME}"/>
            <variable name="LD_LIBRARY_PATH" value="${REMOTE_HOME}/${SCILAB_HOME}/bin"/>
          </environment>
          <processReference refid="localJVM"/>
        </rshProcess>
      </processDefinition>
      <processDefinition id="rsh_trinidad">
        <rshProcess class="org.objectweb.proactive.core.process.rsh.RSHProcess" hostname=
"trinidad">
          <environment>
            <variable name="SCIDIR" value="${REMOTE_HOME}/${SCILAB_HOME}"/>
            <variable name="SCI" value="${REMOTE_HOME}/${SCILAB_HOME}"/>
            <variable name="LD_LIBRARY_PATH" value="${REMOTE_HOME}/${SCILAB_HOME}/bin"/>
          </environment>
          <processReference refid="localJVM"/>
        </rshProcess>
      </processDefinition>
      <processDefinition id="rsh_apple">
        <rshProcess class="org.objectweb.proactive.core.process.rsh.RSHProcess" hostname="apple"
>
          <environment>
            <variable name="SCIDIR" value="${REMOTE_HOME}/${SCILAB_HOME}"/>
            <variable name="SCI" value="${REMOTE_HOME}/${SCILAB_HOME}"/>
            <variable name="LD_LIBRARY_PATH" value="${REMOTE_HOME}/${SCILAB_HOME}/bin"/>
          </environment>
          <processReference refid="localJVM"/>
        </rshProcess>
      </processDefinition>                        
    </processes>
  </infrastructure>
</ProActiveDescriptor>

Example 43.2. Descriptor deployment

43.3. Graphical User Interface (Scilab Grid ToolBox)

This interface allows to manipulate the functionnalities of the API in a user friendly way.

43.3.1. Launching Scilab Grid ToolBox

To launch the application, you have to execute the script:

On Unix:

cd scripts/unix
scilab.sh

On Windows:

cd scripts\windows
scilab.bat

if you use a local version of Scilab, you must declare the environment variables in the file:

scripts/[unix|windows]/scilab_env.[sh|bat]

Once the application is started, the main frame is displayed. This frame is composed in three parts:

  • The tree of Scilab engines .

  • The ltables of pending, running, and terminated tasks.

  • The text area to display the log of user operations.

Main frame

Figure 43.1. Main frame

43.3.2. Deployment of the application

The first step is to deploy the topology of the application. A dialog enables to choice the descriptor and to select the virtual node. The button "deploy" launches the deployment of scilab engine over the nodes.

Deployment of the application

Figure 43.2. Deployment of the application

43.3.3. Task launching

The next step is the task launching. A dialog enables to select the script and possibly to define the script initialization, the return values, and the task priority. The button start creates and sends the task.

Creation of a task

Figure 43.3. Creation of a task

43.3.4. Display of results

The last step is the display of results. A double click on a task in the table of terminated tasks sets visible a dialog. This dialog displays the tasks properties and the result (with the possibility to save it in a file)

Display a result

Figure 43.4. Display a result

43.3.5. Task monitoring

In the main frame, several tables of tasks (pending, executing , terminated) allow to monitor the application. These tables allows to show just for each task the relevant informations. A double click on a task in these tables sets visible a dialog. This dialog displays the tasks properties (path, script initialization, results).

  • The table of pending tasks enables to cancel selected tasks and to clear all cancelled tasks

  • The table of executing tasks enables to kill selected tasks and to clear all killed tasks

  • The table of terminated tasks enables to get the status of tasks (SUCCESS or ABORT), to save the first selected task in file the result, to remove selected tasks.

43.3.6. Engine monitoring

In the main frame, a tree describes all nodes used by the application. Over the execution of the application, if a task is aborted, the engine of this task may be unstable ( this one is displayed with a red foreground). A rigth-click on it show a popup menu to restart it.

State of Engines

Figure 43.5. State of Engines