C++ or MATLAB or Java or other for very complicated Mathematical operations in Physical Chemistry lasting for days, months or even years?

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

In general, problem of MATLAB is in for loops that cause some slowness. If while loops are used instead of for loops, speed will be increased very much (some complicated tests can be very interesting) and additionally, while loops are more flexible than for loops and therefore, MATLAB, will be an excellent friend for a programmer with very complicated mathematical calculations and operations. Additionally, because of existence of MATLAB Coder toolbox, it's unnecessary to follow C++ for these complicated calculations. In fact, in early future, C++ with respect to MATLAB, will be like Assembly with respect to C++. Only MATLAB. Thanks God for such a powerful software and I wish God's attentions and helps for its kind engineers.
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.

Sign in to comment.

Answers (2)

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

I can write very complicated mathematical programs that I need in physical chemistry and if I continue this trend, I will be very skillful in it in future, God-Willing, but some people say that this isn't very worthy because 1) for large-scale programs, specially programs full of loops, isn't very good in speed, even by using mex-files; 2) flexibility in programming isn't like a language like C++; 3) creation of a mathematical software (package) through it, isn't portable and requires installing matlab on target computer.
I think, because of existence of MATLAB Coder toolbox, it's unnecessary for me to follow C++. What a Great Chance. In fact, in early future, C++ with respect to MATLAB, will be like Assembly with respect to C++.
MATLAB Coder is quite restricted. It cannot handle cell arrays for example, and it cannot handle graphics.

Sign in to comment.

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

Tags

Asked:

on 15 Jan 2014

Commented:

on 25 Jan 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!