From: Michel T. <ta...@lp...> - 2021-06-18 12:18:40
|
Hello, since recently gentran is becoming fashionable, i have investigated the possibility of using gentran and external programs to help doing calculations in maxima, using cffi. It took me a lot of time because the documentation of cffi is more oriented to show that the authors are very smart than to explain how to use cffi in many different use cases in a direct way. Moreover i encountered a bug, there is a variable err in the external program which confuses a variable *err* somewhere in lisp, and gives a message "memory corrupted" which is not very informative. Anyways i took as an example the program intde (integration with double exponential approch to the limits) that D. Prodanov advocated here recently, because it is quite simple and at the same time presents the same type of problems encountered in many computational problems, namely there are functions called via function pointers and results returned via pointers. I have worked with the C version of gentran , that is setting gentranlang:c; because i am more used to C than Fortran, and the declarations of cffi are close to the C declarations. Note that gentran does not output the necessary declarations so the the program compiles, and one has to put them by hand. An interesting point about intde is that the author provide both C code and Fortran code and one can see the great parallelism between the two (see the package in http://www.kurims.kyoto-u.ac.jp/~ooura/intde.html). All this i have run under Ubuntu 20.04 Maxima 5.43.2 http://maxima.sourceforge.net using Lisp SBCL 2.0.1.debian quipped with clang and gcc, i have no idea how it works on other platforms and i don't care at all. I have just tried loading quicklisp under clisp and it did not work, complaining about the asdf version. You can find attached the integration program intde1.c, a program tot.c which contains the function f to be integrated and can also be run directly to show the value of the integral, finally a maxima program intdetest.mac which does the cffi business and computes the same integral under cffi control, so that the result can be used elsewhere in maxima. This is obviously not very useful for intde, but may be very useful for compute intensive programs like colnew. Hoping this may be a useful example for people wanting to pursue the idea. -- Michel Talon |