C++ or MATLAB or Java or other for very complicated Mathematical operations in Physical Chemistry lasting for days, months or even years?
Show older comments
C++ or MATLAB or Java or other for very complicated mathematical operations from standpoints of speed and flexibility in writing? (some mathematical operations in physical chemistry lasting for days, months or even years.).
2 Comments
Walter Roberson
on 25 Jan 2014
In modern MATLAB, "for" loops can be even faster than while loops, in that "for" loops are able to predict that memory needs to be pre-allocated.
Answers (2)
Sean de Wolski
on 15 Jan 2014
Edited: Sean de Wolski
on 15 Jan 2014
Your description is really too vague to give you an answer. Remember, you need to include:
requirements time + development time + debugging time + running time
Pick the language that will minimize this. If you're proficient in MATLAB, or not proficient in the others, it will certainly give you a better development plus debugging time. If you have Parallel Computing Toolbox and/or write your code well, it could give you the best running time as well - especially compared to developing your own MPI or OpenMP code. If you need even more speed, depending on what you're doing, there's also MATLAB Coder which will allow you to generate C-Code which you could then compile and run to see the speedups of a compiled language.
There are many options all of which could work.
3 Comments
Hamid
on 16 Jan 2014
Hamid
on 25 Jan 2014
Walter Roberson
on 25 Jan 2014
MATLAB Coder is quite restricted. It cannot handle cell arrays for example, and it cannot handle graphics.
Walter Roberson
on 25 Jan 2014
0 votes
All three languages run the risk of internal library bugs (or user bugs) that "leak" memory. One advantage of C++ is that there are tools available that can analyze memory usage well and detect whether the particular data in the run triggered a leak and where the leaked memory was allocated.
For all three languages, it would be recommended that you use a "checkpoint" mode of operation, or a "journalling" mode of operation.
"checkpoints" are the practice of occasionally writing out state information that is extensive enough that you could interrupt the program (power failure, cosmic rays, hardware burp, whatever reason) and resume it from the last checkpoint without losing "much" time.
"journalling" is suitable for the case where a program generates state updates to a resource (such as a database) and it is important to be able to "replay" the updates in case of interruption (or in the case of financial databases, if a transaction got revoked).
If you are processing multiple files, then at the very least you should have your program mark each file that has already been processed so that upon restart it does not have to be done again. A simple but effective method is to have a directory of files needing to be processed, and as processing finishes on a file, move it to a directory of completed files.
These days, if you have a long-running program, you should be considering running it on a FPGA or on GPU. Or designing custom chips optimized for the program logic.
Categories
Find more on Chemistry in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!