Timing comparison for diffeq program in c++, Maple and Maxima



I commented out the generation of all the "mode_declares"
Got 394 iterations in 60 second (on same problem as before)
Ii.e. 6.6 iterations/second.

I had a lot of trouble with arrays in maxima.
I was trying to pass them as parameters at first.
As most of you probably know in c, most things (say integers, or floats) are passed by value, but for arrays, the address of the array is passed as the value. Thus you can change what is pointed to. (If you wanted to change an int, you would pass the address of the int, not the int itself).

It seems, in maxma (the best I can describe it - if there is a better way please let me know). Arrays are passed by value also.

I thus only use arrays on a global manner. (They seem automatically have this scope) I never pass them as parameters. This I also do in the generated Maple and c++ code. In cases I need to do the same sort of thing of two different arrays I generate the same code - once for each array. This would be a big problem if I were writing the code by hand. It is not when a program generates the code. The code is probably faster - fewer function calls. The code will take more memory, but will use less stack. Anyway that solved the problem with arrays.

I had just been interpreting the maxima code. I just tried to compile it and it did not like where I had a "declare_variable".(The 1st one)

I will look further at bfloats. I was pretty sure I had problems with them, but that was early on and I had other problems then. I can do that separate from the ODE code.
?
Dennis J. Darland

dennis.darland at yahoo.com

http://dennisdarland.com/

http://dennisdarland.com/dennisdaze/

http://dennisdarland.com/philosophy/

http://sode.sourceforge.net/

"According to the World Health Organization, the warming of the planet caused an additional 140,000 deaths in 2004, as compared with the number of deaths there would have been had average global temperatures remained as they were during the period 1961 to 1990. This means that climate change is already causing, every week, as many deaths as occurred in the terrorist attacks on September 11, 2001"

-- Peter Singer _Practical Ethics, Third Edition_, p. 216.

--- On Thu, 8/9/12, Stavros Macrakis <macrakis at alum.mit.edu> wrote:

From: Stavros Macrakis <macrakis at alum.mit.edu>
Subject: Re: [Maxima] Timing comparison for diffeq program in c++, Maple and Maxima
To: "Dennis Darland" <dennis.darland at yahoo.com>
Cc: maxima at math.utexas.edu, "Rupert Swarbrick" <rswarbrick at gmail.com>
Date: Thursday, August 9, 2012, 10:34 AM

A quick look at your code shows that the only mode_declare's are mode_declare(f,bfloat), where f is a function. There are several problems with this:

* That is not the correct syntax for mode_declare of a function.
* bfloat is not one of the types that mode_declare understands (and in fact it gives a warning for this).* In any case, bfloat calculation is going to be about equally expensive whether compiled or interpreted.

I haven't looked closely, but I also get the impression that you're using arrays incorrectly. ?Please don't assume that Maxima arrays behave the same as C, Fortran, or Maple arrays. ?They do not. ?Some of the differences are certainly idiosyncratic, but that's what they are for now....

Without declarations for machine types (notably float and fixnum) for your variables and arrays, Maxima assumes fully general symbolic calculations, which are expensive.

Again, I haven't looked at your code in detail, but where do you actually compile all the functions anyway?

I would suggest that you start with some "finger exercises" on smaller cases before trying to run your full DE code. ?Also not clear why you want to do this in Maxima at all if you're using none?of its symbolic capabilities. ?Mixed symbolic/numeric calculations are another matter....

? ? ? ?-s
On Thu, Aug 9, 2012 at 10:18 AM, Dennis Darland <dennis.darland at yahoo.com> wrote:

I am using just basic math like you say. In maple I can use higher precision floating point by setting "Digits". (Though it only seems to work up to about 32 digits). I expected to be able to do something similar in Maxima. Maxima does have "big floats". I tried them, but, as far as I could tell, they did not support trig functions, etc. (You only get about 16 digits and a lot of warning messages). ?If ?big floats can me made to support trig functions, etc., I would like to know about it. I plan to look also for a c++ library for extended precision floating point numbers. I am also interested in what is called "interval arithmetic."




I also used Maxima as well as Maple as it is more affordable, and I like to support open source. I am not trying to criticize Maple or Maxima, only to ascertain the facts. It is interesting that c++ is so much faster, in that it makes solving some problems more practical.




The program was debugged in Maple and Maxima together. Both, in some cases gave better error messages than the other. I doubt I could have debugged it in c or c++, which most likely have crashed instead of giving an error message. (The code to generate c or c++ is not released yet, as I am just beginning to test it, but it seems to work OK so far)




The reason I started subscripts at 1 was Dr Chang's work started subscripts at 1, and thus it was a lot easier. I used the formulas from his draft of a book he started. He was working in FORTRAN, but my program is not at all a translation of his program. (He wrote as program in FORTRAN which generated a FORTRAN program,) His program is beyond my comprehension. ?Also other languages I may want to use in the future may not permit "0" subscripts. I doubt I will ever support FORTRAN.




Dennis J. Darland

dennis.darland at yahoo.com

http://dennisdarland.com/

http://dennisdarland.com/dennisdaze/

http://dennisdarland.com/philosophy/

http://sode.sourceforge.net/

"According to the World Health Organization, the warming of the planet caused an additional 140,000 deaths in 2004, as compared with the number of deaths there would have been had average global temperatures remained as they were during the period 1961 to 1990. This means that climate change is already causing, every week, as many deaths as occurred in the terrorist attacks on September 11, 2001"


-- Peter Singer _Practical Ethics, Third Edition_, p. 216.





--- On Thu, 8/9/12, Rupert Swarbrick <rswarbrick at gmail.com> wrote:



> From: Rupert Swarbrick <rswarbrick at gmail.com>

> Subject: Re: [Maxima] Timing comparison for diffeq program in c++, Maple and Maxima

> To: maxima at math.utexas.edu

> Date: Thursday, August 9, 2012, 7:32 AM

> Dennis Darland <dennis.darland at yahoo.com>

> writes:

> > I ran a timing test comparison for c++, Maple and

> Maxima.

> > All three programs generated by omnisode - a set of

> Ruby programs.

> > Set time limit to 1 minute.

> > Maximum iteration was sufficient to solve entire

> problem.

> > Problem was sin.ode for all three.

> > Output was redirected to file only - none to screen

> > Results:

> > c++ solved entire problem in 23 seconds (140001

> iterations)

> > Maple performed 11542 iterations in 60 seconds

> > Maxima performed 372 iterations in 60 seconds

> > That amounts to:

> > c++ 6,087 iterations/second

> > Maple 192 iterations/second

> > Maxima 6.2 iterations/second

> > c++ is almost 32 times faster than Maple which is

> almost 31 times faster than Maxima.

> > So c++ is almost 982 times faster than Maxima.

> >

> > More info on omnisode at:

> > http://sode.sourceforge.net/

>

> Right, I just tried to look up the Maxima code you're

> generating and

> found things like [1]. Since I'm clearly not going to read

> through that

> carefully, and I presume no-one else is either, can you

> explain exactly

> what you're measuring?

>

> Your code looks to me like a C/FORTRAN program translated

> to

> Maxima. Unsurprisingly, it runs very slowly. What are you

> actually

> trying to do? What capabilities of Maple or Maxima are you

> using other

> than basic arithmetic?

>

> Or should we interpret your message as

>

> ? "Writing bare-metal calculations in Maple and running

> them is

> ???marginally less slow that writing them in

> Maxima and running

> ???them. But it would have been easier to do

> it in C anyway"

>

> ??

>

>

> Rupert

>

> [1] http://sode.sourceforge.net/omniresults/special_cases_007/diffeq.tan_sqrt_lin.mxt.txt

>

> -----Inline Attachment Follows-----

>

> _______________________________________________

> Maxima mailing list

> Maxima at math.utexas.edu

> http://www.math.utexas.edu/mailman/listinfo/maxima

>

_______________________________________________

Maxima mailing list

Maxima at math.utexas.edu

http://www.math.utexas.edu/mailman/listinfo/maxima