Archive for the ‘Maple’ Category
Maple has had support for NVidia GPUs since version 14 but I’ve not played with it much until recently. Essentially I was put off by the fact that Maple’s CUDA package seemed to have support for only one function – Matrix-Matrix Multiplication. However, a recent conversation with a Maple developer changed my mind.
It is true that only MatrixMatrixMultiply has been accelerated but when you flip the CUDA switch in Maple, every function in the LinearAlgebra package that calls MatrixMatrixMultiply also gets accelerated. This leads to the possibility of a lot of speed-ups for very little work.
So, this morning I thought I would take a closer look using my laptop. Let’s start by timing how long it takes the CPU to multiply two 4000 by 4000 double precision matrices
with(LinearAlgebra): CUDA:-Enable(false): CUDA:-IsEnabled(); a := RandomMatrix(4000, datatype = float[8]): b := RandomMatrix(4000, datatype = float[8]): t := time[real](): c := a.b: time[real]()-t
The exact time varied a little from run to run but 3.76 seconds is a typical result. I’m only feeling my way at this stage so not doing any proper benchmarking.
To do this calculation on the GPU, all I need to do is change the line
CUDA:-Enable(false):
to
CUDA:-Enable(true):
like so
with(LinearAlgebra): CUDA:-Enable(true): CUDA:-IsEnabled(); a := RandomMatrix(4000, datatype = float[8]): b := RandomMatrix(4000, datatype = float[8]): t := time[real](): c := a.b: time[real]()-t
Typical execution time was 8.37 seconds so the GPU version is more than 2 times slower than the CPU version on my machine.
Trying different matrix sizes
Not wanting to admit defeat after just a single trial, I timed the above code using different matrix sizes. Here are the results
- 1000 by 1000: CPU=0.07 seconds GPU=0.17 seconds
- 2000 by 2000: CPU=0.53 seconds GPU=1.07 seconds
- 4000 by 4000: CPU=3.76 seconds GPU=8.37 seconds
- 5000 by 5000: CPU=7.44 seconds GPU=19.48 seconds
Switching to single precision
GPUs do much better with single precision numbers so I had a try with those too. All you need to do is change
datatype = float[8]
to
datatype = float[4]
in the above code. The results are:
- 1000 by 1000: CPU=0.03 seconds GPU=0.07 seconds
- 2000 by 2000: CPU=0.35 seconds GPU=0.66 seconds
- 4000 by 4000: CPU=1.86 seconds GPU=2.37 seconds
- 5000 by 5000: CPU=3.81 seconds GPU=5.2 seconds
So the GPU loses in single precision mode too on my hardware. If I can’t get a speedup with MatrixMatrixMultiply on my system then there is no point in exploring all of the other LinearAlgebra routines since all of them will be slower when moving to CUDA acceleration.
I guess that in this case, my CPU is too powerful and my GPU is too wimpy to see the acceleration I was hoping for.
Thanks to Maplesoft for providing me with a review copy of Maple 15.
Test System Specification
- Laptop model: Dell XPS L702X
- CPU: Intel Core i7-2630QM @2Ghz software overclockable to 2.9Ghz. 4 physical cores but total 8 virtual cores due to Hyperthreading.
- GPU: GeForce GT 555M with 144 CUDA Cores. Graphics clock: 590Mhz. Processor Clock:1180 Mhz. 3072 Mb DDR3 Memeory
- RAM: 8 Gb
- OS: Windows 7 Home Premium 64 bit.
- Maple 15
My attention was recently drawn to a Google+ post by JerWei Zhang where he evaluates 2^3^4 in various packages and notes that they don’t always agree. For example, in MATLAB 2010a we have 2^3^4 = 4096 which is equivalent to putting (2^3)^4 whereas Mathematica 8 gives 2^3^4 = 2417851639229258349412352 which is the same as putting 2^(3^4). JerWei’s post gives many more examples including Excel, Python and Google and the result is always one of these two (although to varying degrees of precision).
What surprised me was the fact that they disagreed at all since I thought that the operator precendence rules were an agreed standard across all software packages. In this case I’d always use brackets since _I_ am not sure what the correct interpretation of 2^3^4 should be but I would have taken it for granted that there is a standard somewhere and that all of the big hitters in the numerical world would adhere to it.
Looks like I was wrong!
Typical…I leave my iPad at home and this happens
I can’t WAIT to try this out. Blog post from Maplesoft about it at http://www.mapleprimes.com/maplesoftblog/127071-Maple-And-The-IPad?sp=127071
May I be the first to ask “When is an Android version coming out?”
Updated January 4th 2011
It is becoming increasingly common for programmers to make use of GPUs (Graphical Processing Units) to speed up their programs substantially. There are three major low-level programming libraries that allow you to do this in languages such as C; namely CUDA, OpenCL and Microsoft DirectCompute. Of these three, CUDA is the most developed but it only works on Nvidia graphics cards.
I am often asked if the major commercial math packages support GPU computing and I find myself writing the same summary email over and over again. So, here is a very brief breakdown of what is currently on offer. I plan to expand the information contained in this page over time so if you have any information about GPU computing in these packages then let me know.
MATLAB
Core MATLAB contains no support for GPU computing but several organizations (including The Mathworks themselves) have produced add-on toolboxes that add such support:
- Jacket – This is a product from a company called AccelerEyes and is possibly the most advanced and well developed GPU solution for MATLAB currently available. As of version 2.0 it supports both OpenCL and CUDA frameworks.
- The Mathworks’ Parallel Computing Toolbox (PCT) – If you want to do your MATLAB GPU computing the officially supported way then this is the product you need. As a bonus, it also allows you to make better use of the multicore processor that almost certainly resides in your machine. Like many of the offerings on this page, only the CUDA framework is supported so you are out of luck if you don’t have an NVidia graphics card. Even if you do have an NVidia graphics card then you still might be out of luck since the PCT only supports cards that have compute level 1.3 or above (i.e. double precision only).
- CULA is a set of GPU-accelerated linear algebra libraries utilizing the NVIDIA CUDA parallel computing architecture and it has a MATLAB interface.
- GPUmat – This product is completely free but is less developed than the commercial offerings above. Again. it is CUDA only
- OpenCL toolbox – The only OpenCL solution for MATLAB I could find. It is free but development seems to have stalled.
Mathematica
Mathematica 8 has support for both CUDA and OpenCL built in so no need for any add-ons. Furthermore, it supports both single and double precision GPUs so you can experiment with GPU computing on older, cheaper cards.
Maple
Maple has had some CUDA-only GPU support since version 14. On the face of it, the CUDA package only appears to contain one accelerated function–Matrix-Matrix multiplication– but when you load this function it accelerates many functions that use matrix-matrix multiply internally. I’ve never found a definitive list of such functions though.
Mathcad
Mathcad 15 and Mathcad Prime have no support for GPU enhanced computing.
Christmas isn’t all that far away so I thought that it was high time that I wrote my Christmas list for mathematical software developers and vendors. All I want for christmas is….
Mathematica
- A built in ternary plot function would be nice
- Ship workbench with the main product please
- An iPad version of Mathematica Player
MATLAB
- Merge the parallel computing toolbox with core MATLAB. Everyone uses multicore these days but only a few can feel the full benefit in MATLAB. The rest are essentially second class MATLAB citizens muddling by with a single core (most of the time)
- Make the mex interface thread safe so I can more easily write parallel mex files
Maple
- More CUDA accelerated functions please. I was initially excited by your CUDA package but then discovered that it only accelerated one function (Matrix Multiply). CUDA accelerated Random Number Generators would be nice along with fast Fourier transforms and a bit more linear algebra.
MathCAD
- Release Mathcad Prime.
- Mac and Linux versions of Mathcad. Maple,Mathematica and MATLAB have versions for all 3 platforms so why don’t you?
NAG Library
- Produce vector versions of functions like g01bk (poisson distribution function). They might not be needed in Fortran or C code but your MATLAB toolbox desperately needs them
- A Mac version of the MATLAB toolbox. I’ve got users practically begging for it :)
- A NAG version of the MATLAB gamfit command
Octave
- A just in time compiler. Yeah, I know, I don’t ask for much huh ;)
- A faster pdist function (statistics toolbox from Octave Forge). I discovered that the current one is rather slow recently
SAGE Math
- A Locator control for the interact function. I still have a bounty outstanding for the person who implements this.
- A fully featured, native windows version. I know about the VM solution and it isn’t suitable for what I want to do (which is to deploy it on around 5000 University windows machines to introduce students to one of the best open source maths packages)
SMath Studio
- An Android version please. Don’t make it free – you deserve some money for this awesome Mathcad alternative.
SpaceTime Mathematics
- The fact that you give the Windows version away for free is awesome but registration is a pain when you are dealing with mass deployment. I’d love to deploy this to my University’s Windows desktop image but the per-machine registration requirement makes it difficult. Most large developers who require registration usually come up with an alternative mechanism for enterprise-wide deployment. You ask schools with more than 5 machines to link back to you. I want tot put it on a few thousand machines and I would happily link back to you from several locations if you’ll help me with some sort of volume license. I’ll also give internal (and external if anyone is interested) seminars at Manchester on why I think Spacetime is useful for teaching mathematics. Finally, I’d encourage other UK University applications specialists to evaluate the software too.
- An Android version please.
How about you? What would you ask for Christmas from your favourite mathematical software developers?
Version 14 of Maple was released a couple of weeks ago and it appears to have some very cool stuff in it. Some of the highlights that stand out for me include
- Accelerated linear algebra using graphics cards via NVIDIA’s CUDA. Maple’s advertising blurb says that they have implemented matrix multiplication and that this will help speed up many linear algebra routines since this is such a fundamental operation. I think that Maple are the first of the big general purpose mathematical packages to offer direct CUDA integration out of the box and this development is well worth watching. The speed-ups that are possible from CUDA technology are nothing short of astonishing – hundreds of times in some cases. However, Maplesoft are going to need to add a lot more than matrix multiplication in order for this to be truly useful. A set of fast random number generators would be nice for example (I’m thinking superfast Monte-carlo simulations – the finance people would love it).
- Maple uses Intel’s Math Kernel Library (MKL) for many of its low-level numerical linear algebra routines and this has been updated to version 10.0 in Maple 14. For 32bit windows users this has sped certain operations up quite a lot but it is 64bit Windows users who will really see the benefit since 64bit Maple 13 only used a set of generic BLAS routines. The practical upshot is that certain basic linear algebra routines, such as Matrix Multiplication, can be around 10 times faster in 64bit windows Maple 14 compared to the previous version. I couldn’t find mention of the Linux version.
- A shed load of updates to their differential equation solvers including a new numerical routine called the Cash-Karp pair.
- The Maple toolbox for MATLAB is no longer a separate product and is now included with Maple itself. This is great news if you, like me, tend to work with several mathematical packages simultaneously. Of course you need to have a copy of MATLAB installed to make use of this functionality – you don’t get a copy of MATLAB for free :)
- You can now import MATLAB binary files (compressed and uncompressed) directly into Maple using the ImportMatrix command.
- Another product, The Maple-NAG connector, has also been integrated with Maple itself. This allows you to easily call the NAG C library directly from Maple but, similar to the MATLAB toolbox, you’ll have to purchase the NAG C library separately to make use of this.
As you can see, I tend to favour new features that lead to improved performance or better interoperability with other software packages in the first instance. New mathematics and usability features take a little longer to sink in (for me at least).
I’ve not got a copy of Maple 14 yet but will try to write more if I upgrade (finances permitting).
For a full list of changes check out Maple’s online help section.
More on Maple from Walking Randomly
Maplesoft have been getting into the Christmas spirit recently with a few festive demonstrations. The first uses MapleSim (essentially Maple’s answer to Simulink) to simulate Santa in flight. Of course it is highly simplified since, among other things, the model doesn’t simulate the weight of the presents which will (obviously) be steadily decreasing throughout Christmas Eve. It is, however, a great start.
Slightly more practically, they have used Maple to derive a new rule of thumb for the cooking time of turkeys. The traditional rule of thumb is to allow 20 minutes per pound of turkey if you cook at 350° F (after pre-heating to 400° F) although there is a variation to this rule that suggests adding an extra 15 minutes to the final cooking time. According to Maplesoft’s analysis, this is great if your turkey is somewhere between 9 and 14 pounds in weight but if you use it to cook larger turkeys then you may find that the result is overcooked and dry.
After a bit of analysis, Maplesoft have suggested that if the weight of your turkey is x pounds then the ideal cooking time is 45*x^(2/3) minutes. So, using the new rule on a 10 pound turkey gives 45*10^(2/3) = (approx) 209 minutes compared to 200 minutes using the old rule – not much difference there then.
On a 20 pound turkey, however, the difference is more pronounced: 400 minutes using the old rule but 332 minutes using the new rule! Now, the Maple engineer who derived this equation admits that he hasn’t tried it out in the kitchen yet but he will do so this Christmas and I think that I might try it too if I get the chance. If you are a cook and have tried this new formula for large turkeys then let me know how you got on.
Please consider this formula to be experimental for now though and CHECK that your turkey is cooked before eating it. Remember that the equation hasn’t been checked in the kitchen yet!
For more examples of festive mathematical programs created with software such as Mathematica, Maple, MATLAB and SAGE check out the following links.
Almost every computer you buy these days contains more than one processor core – even my laptop has 2 – and I have access to relatively inexpensive desktops that have as many as 8. So, it is hardly surprising that I am steadily receiving more and more queries from people interested in making their calculations run over as many simultaneous cores as possible.
The big three Ms of the mathematical software world, Mathematica, Maple and MATLAB, all allow you to explicitly parallelise your own programs (although you have to pay extra if you want to do this in MATLAB without resorting to hand crafted C-code) but parallel programming isn’t easy and so tutorials are invaluable.
Fortunately, Darin Ohashi, a senior kernel developer at Maplesoft has taken the time to write some parallel Maple tutorials for us and he has presented his work as a series of blog posts over at MaplePrime. Here’s an idex:
- The Parallel Programming Blog
- Why Go Parallel?
- What Makes Parallel Programming Hard?
- Thread Safety
- Load Balancing and Thread Management
- The Task Programming Model
- Parallel Programming Blog Feedback
If you are interested in parallel programming in Maple then Darin’s posts are a great place to start.
Other articles from Walking Randomly you may be interested in
Maplesoft, developers of the popular computer algebra system – Maple, have been bought by Cybernet Systems Co., Ltd., a Tokyo-based major Japanese importer/distributor of CAE (computer aided engineering) software. More details here.
I just hope that this turns out to be a good thing. I like Maple and I don’t want it messed up!
OK, so with today’s release of Maple version 13, this blog post is a little late but I started so I’ll finish! My original install of Maple was 12.01 on Ubuntu Linux and a little while ago an update was released to take this to version 12.02.
Installation
In theory I should be able to install this automagically by clicking on Tools->Check for Updates inside Maple. However, when I did this I was told that ‘no updates were currently available‘ so I had to download the update manually from here. I was very pleased to note that this update was offered free of charge to all Maple 12 users. This is exactly as it should be and other software vendors should take note here – users don’t like paying for bug-fix updates! Well done to Maplesoft for doing it right. Once I had downloaded the 12.02 update installer, the installation itself was pretty straightforward. The following incantations did the trick for me
chmod +x ./Maple1202Linux32Upgrade.bin sudo ./Maple1202Linux32Upgrade.bin
A graphical installer fired up and all I had to do was click Next a couple of times and point it to my Maple 12.01 installation. A few seconds later it was all over. It’s a shame that the automatic checker didn’t work but all in all this was a very painless experience!
Now since this update only increments the version number by 0.01 you shouldn’t be expecting any marvellous new features. What you should be expecting is some tidying up and bug fixing and that is exactly what you get. Maplesoft’s own description of the bug-fixes weren’t detailed enough for my tastes and so I appealed to my informants at Maplesoft for something more explicit.
Happily, they delivered and most of what follows is from them. Thanks Maplesoft :)
Since 12.02 was released along with the launch of MapleSim, many of the updates were geared towards symbolic manipulation and simplification, which is always beneficial for any advanced computations, but very important for MapleSim. As such, the best examples to illustrate the updates are in MapleSim, and are not easily shown with a Maple example alone. More specifically though, there were other enhancements and fixes that were added to Maple 12.02 to help improve it, which are not tied directly to MapleSim:
Updates to dsolve
There were two significant issues present in Maple 12.01 and earlier that are not present in Maple 12.02. One of these deals with a certain class of singularities that are transparent to explicit rk-pair based numerical solvers.
As the simplest example in this class, the differential system:
dsys := {diff(x(t),t)=x(t)/(1-t),x(0)=1};

having the exact solution:
dsolve(dsys);

has a singularity at t=1, and exactly ’0′ error according to explicit rk-pair error estimation.
This, and other related singularities (such as jump discontinuities) are now detected to provide an accurate numerical solution. Compare this output from 12.01
dsn := dsolve(dsys, numeric);
dsn := proc(x_rkf45) ... end proc
dsn(0.999);
[t = .999, x(t) = -48.3295522342053872]
dsn(1.001);
[t = 1.001, x(t) = -48.4646844943701609]
with the improved output from 12.02
dsn := dsolve(dsys, numeric);
dsn := proc(x_rkf45) ... end proc
dsn(0.999);
[t = 0.999, x(t) = 1000.00023834227034]
dsn(1.001);
Error, (in dsn) cannot evaluate the solution further right of .99999999, probably a singularity
The second fix deals with error control on index-1 (non-differential) variables in the problem. This can be seen if you take a trivial problem coupled with a non-trivial index-1 variable. For example: In Maple 12.01:
dsys := {diff(x(t),t)=1, y(t)=sin(t), x(0)=0}:
dsn := dsolve(dsys, numeric):
dsn(Pi);
[t = 3.14159265358979, x(t) = 3.14159265358978956,
y(t) = -0.00206731654642018647]
dsn(2*Pi);
[t = 6.28318530717958, x(t) = 6.28318530717958357,
y(t) = -0.0623375491269087187]
The ‘y’ value should have been zero. In Maple 12.02:
dsys := {diff(x(t),t)=1, y(t)=sin(t), x(0)=0}:
dsn := dsolve(dsys, numeric):
dsn(Pi);
[t = 3.14159265358979, x(t) = 3.14159265358978956,
y(t) = -0.117631599366556372 10^-6 ]
dsn(2*Pi);
[t = 6.28318530717958, x(t) = 6.28318530717958090,
y(t) = -0.130170125786817359 10^-6 ]
which is zero within the default error tolerances.
Plot Annotations bug fix
In 12.01, some plot annotations were not appearing as expected. When a text box was entered on a 2D plot, the text would not appear until focus was taken away from the text box itself. For example, if you were to create a plot of sin(x) plot(sin(x)) and then click on the plot, select drawing from the toolbar and then select ‘T’ to enter a text field, you could begin typing, but would not receive visual feedback of what you entered until you clicked outside of the textbox. Obviously, this was a bug, and it was fixed in 12.02.
Improvements to embedded components
Prior to 12.02, some installations of Linux displayed some issues with redrawing of various embedded components, which slowed down scrolling in a Maple document. In 12.02, Maplesoft added a few fixes to the way that they handle embedded components, especially for 32-bit systems, which took care of this issue for most Linux installations. Also, since they were in the area, they took the opportunity to tweak response times for embedded components when creating them and executing the code that dictates their behavior in a document. This is not *very* noticeable when you have just a few components in a document, but it becomes very visible with Maplesoft’s interactive ebooks and with user applications that rely on a large number of components in a single application.
Excel Link improvements
In Maple, there is a built-in link to Microsoft Excel, so that you can perform Maple computations within an Excel spreadsheet. Maplesoft started supporting Excel 2007 in Maple 12, but with a service pack release to Windows released shortly thereafter and some security enhancements added to Maple, the link did not perform as expected in 12.01. Certain values were being interpreted incorrectly, as such, Maplesoft felt that they needed to address these inconsistencies as soon as possible. So for 12.02, they fixed the link for Excel 2007 to ensure that values were faithfully being passed from Microsoft Excel to Maple, in order to maintain the connection and computation accuracy.



