From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id B5699BBAF for ; Sun, 29 Nov 2009 18:25:19 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvQCAHc9EkuTIMAknGdsb2JhbACBTZpDAQEBAQEICwgctn2EMQSBcg X-IronPort-AV: E=Sophos;i="4.47,308,1257116400"; d="scan'208";a="41039973" Received: from max.feld.cvut.cz ([147.32.192.36]) by mail1-smtp-roc.national.inria.fr with ESMTP; 29 Nov 2009 18:25:19 +0100 Received: from localhost (unknown [192.168.200.4]) by max.feld.cvut.cz (Postfix) with ESMTP id 47A4D19F33AA; Sun, 29 Nov 2009 18:25:18 +0100 (CET) X-Virus-Scanned: IMAP AMAVIS Received: from max.feld.cvut.cz ([192.168.200.1]) by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new, port 10044) with ESMTP id cv8NbGSI3xLs; Sun, 29 Nov 2009 18:25:14 +0100 (CET) Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34]) by max.feld.cvut.cz (Postfix) with ESMTP id E6E3419F33B2; Sun, 29 Nov 2009 18:25:13 +0100 (CET) Received: from localhost.fel.cvut.cz (meyer.felk.cvut.cz [147.32.84.20]) (Authenticated sender: kybicjan) by imap.feld.cvut.cz (Postfix) with ESMTPSA id 5D26FFA003; Sun, 29 Nov 2009 18:25:13 +0100 (CET) To: David MENTRE Cc: caml users Subject: Re: [Caml-list] Looking for information regarding use of OCaml in scientific computing and simulation Reply-To: Jan Kybic From: Jan Kybic In-Reply-To: <3d13dcfc0911250305i43a684e4u5a96ec420b6ce350@mail.gmail.com> (David MENTRE's message of "Wed, 25 Nov 2009 12:05:14 +0100") References: <3d13dcfc0911250305i43a684e4u5a96ec420b6ce350@mail.gmail.com> Date: Sun, 29 Nov 2009 00:23:14 +0100 Message-ID: <87ocmmdyjh.fsf@fel.cvut.cz> User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam: no; 0.00; ocaml:01 ocaml:01 snippets:01 bindings:01 pointers:01 bindings:01 blas:01 lapack:01 gsl:01 gnuplot:01 camlimages:01 rewriting:01 ocaml's:01 high-level:01 polymorphism:01 > 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. Yours, Jan -- ------------------------------------------------------------------------- Jan Kybic tel. +420 2 2435 5721 http://cmp.felk.cvut.cz/~kybic ICQ 200569450