Two and half implementations of a scilab wrapper without any compilation

Hi,

In a post on the user list, one asks for an easy way to wrap a scilab code into an OpenTURNS function. Here are two possibilities:

  • using the generic wrapper
  • using the Python wrapping of OpenTURNS function, in two flavours

There are other possibilities I didn't have time to illustrate.

Even with this simple function (the sum of two floating point values), the generic wrapper is faster than the python wrapper by 34% on a quad-core computer.

Best regards,

Régis LEBRUN

Attachments (6)

Download all attachments as: .zip

Comments

1. souchaud@… -- 2012-08-30 15:28

I have added an example using new distributed python wrapper (scilab_DistributedPythonFunction.tgz).

Here is more precise results (tested on i7 2.3Ghz*8 w/oHT + SSD) :

### scilab alone:
# time scilab -nb -nwni -f code.sce => 0.067s
|
### scilab_with_generic_wrapper with 1000 points
# real minimum computing time (do not launch scilab but sthg like "echo 'y = 3' > result.data"):
# 1 core: 6.9s -> 0.0069 /point
# 2 core: 4.4s -> 0.0088 /p
# 4 core: 3.6s -> 0.0144 /p
# 8 core: 2.4s -> 0.0192 /p
|
# theoric with scilab (scilab alone: time scilab -nb -nwni -f code.sce -> 0.067s)
# 1 core : (0.067+0.0069)*1000 -> 73.9s total
# 8 core : (0.067+0.0192)*1000/8 -> 10.7s total
|
# real with scilab:
# 1 core : 72.8s total -> 0.0728 /p
# 8 core : 9.5s total -> 0.075 /p
# => we are not far from theoric, so the minimum computing time precision is not too bad
# => the generic wrapper is 67/9.5= 7 times faster than the OpenTURNSPythonFunction
|
### scilab_with_OpenTURNSPythonFunction with 1000 points
# real minimal computing time (do not launch scilab):
# 1 core: 0.00415s -> 0.00000415 /point
|
# theoric with scilab (scilab alone: time scilab -nb -nwni -f code.sce -> 0.067s)
# 1 core : (0.067+.00000415)*1000 -> 67s total
|
# real with scilab:
# 1 core : 67.55 total -> 0.0728 /p
# => we are near theoric, so the minimum computing time precision is ok
|
### scilab_with_DistributedPythonFunction with 1000 points
# real minimal compute (do not launch scilab):
# 1 core: 47.6s -> 0.0476 /point
# 8 core: 5.7s -> 0.0456 /p
|
# theoric with scilab (scilab alone: time scilab -nb -nwni -f code.sce -> 0.067s)
# 1 core : (0.067+0.0476)*1000 -> 114s total
# 8 core : (0.067+0.0456)*1000/8 -> 14.1s total
|
# real with scilab:
# 1 core : 153s total ->  0.153 /p
# 8 core : 15.1s total -> 0.120 /p
# => we are not far from theoric, so the minimum computing time precision is not too bad
2. souchaud@… -- 2012-09-04 14:47

Anyway, this scilab example is too simple to be a good benchmark. In this example, scilab could be easily replaced by a pure python function.

With an OpenTURNSPythonFunction wrapper doing the same thing, e.g.:

def _exec(self, X):
    return [X[0] + X[1]]

the compute time would be much faster (x1000) : 0.01 s for 1000 points on 1 core (9.5s on 8 core with scilab_with_generic_wrapper).

3. michael.baudin@… -- 2012-11-06 15:15

Hi,

Thank you for this very interesting post.

Just for clarity, when we execute the Scilab script code.sce, it produces the file result.data, with content :

y = -4.16793252470999960000e-001

The makeWrapper Python function used in scilab_with_generic_wrapper.py is undocumented, as reported at :

http://trac.openturns.org/ticket/477

Regards,

Michaël

4. michael.baudin@… -- 2012-11-08 14:50

On Windows, the Scilab binary is called "Scilex" and not "Scilab", so that the script above does not work. One may use the following code instead:

pltf=platform.system()
if pltf=="Windows":
    params = { "command_" : "scilex -nb -nwni -f code.sce",
               "userPrefix_" : "GenericWrapperTest",
               }
else:
    params = { "command_" : "scilab -nb -nwni -f code.sce",
               "userPrefix_" : "GenericWrapperTest",
               }

Note: I could post the updated "scilab_with_generic_wrapper.py" script, but it seems that only the author of the post can attach files, not commenters.