English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Looking for information regarding use of OCaml in scientific computing and simulation
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-11-29 (17:25)
From: Jan Kybic <kybic@f...>
Subject: Re: [Caml-list] Looking for information regarding use of OCaml in scientific computing and simulation
> I'm considering doing a short presentation of OCaml to my colleagues
> in my research lab. They are working in the telecommunication and
> power electronic sectors, mainly doing signal processing and
> simulations. I know OCaml[1] but not specifically those domains.
> Therefore, I'm looking for reusable material for a presentation:
>  - Slides on the use of OCaml in the signal processing and simulation domains;
>  - Code snippets of OCaml used in scientific computing or simulation,
> typically for advocacy like "it takes 10 lines in OCaml to do this,
> you would use 50 lines in C++ to do the same thing";
>  - Evidence of *actual use* of OCaml for scientific computing or
> simulation, especially regarding usable libraries, bindings, etc.

I am writing this offline, so I cannot provide any pointers now but it
should be easy to find them on the Web.

I used to be a proficient C programmer, currently I am writing a
majority of my code in Ocaml.

There are Ocaml bindings to many libraries for scientific (=numerical)
computing, such as BLAS+LAPACK, GSL, Cubpack, FFTW and others. You can
use MPI for parallel (cluster) programming. For visualization, I have
tried an interface to Gnuplot and OpenGL. For image processing, there
is the CamlImages library.

I have interfaced my Ocaml code with C, C++ (via C), Matlab, and Python.
Because of this interoperability, it is normally relatively easy to
switch to Ocaml gradually, rewriting your programs one by one.

I have been using Ocaml for scientific computing for about seven
years, in domains ranging from solving integral equations to medical
image segmentation (look on my web page for details). However, most of
this is research code (=alpha quality, works good enough for me), so I
am only making it available on request for research purposes. Sadly,
most people that have asked for it have been put off by the fact that
the code was written in Ocaml...

I do not really have any short and self-contained examples of Ocaml's
superiority. My observation is that for simple algorithms based on
high-level operations, I tend to use Matlab or Python, because these
languages are very concise and have comprehensive libraries, and I can
get a proof-of-concept implementation written extremely fast. If
maximum speed is paramount, I write the computational core in
C/C++. Ocaml is the language of choice for me if the algorithm at hand
is complex, uses complicated data structures and/or cannot be
decomposed into a few simple "computational cores". Ocaml is excellent
for this - it is expressive, sufficiently concise, takes care of
memory management, its strong typing prevents many errors and it is
only a few times slower than C (1.5-5, depending on the application).

I used to quote the generalization abilities of Ocaml (polymorphism,
functors, objects) among its advantages, but I have not been using them
much recently because of the rather high computational penalty they
involve. This is in my opinion one of the weak points of Ocaml for
high performance numerical computing.

As for Ocaml syntax, I got used to it. I quite liked the indentation
(Haskel/Python-like) based syntax implemented through the TWT
preprocessor. However, I stopped using it because it interfered with
other preprocessors I wanted to use (e.g. macros in Camlp4) and
sometimes confused error reporting. 

For some projects I have written both Ocaml and C++ implementations
and in all cases writing the Ocaml version was a more enjoyable
experience for me, the code was easier and faster to write and there
were less errors - no segmentation faults. 

If you do prepare some presentation about using Ocaml for scientific
computing, I would be interested in seeing it.



Jan Kybic <kybic@fel.cvut.cz>                       tel. +420 2 2435 5721
http://cmp.felk.cvut.cz/~kybic                      ICQ 200569450