Click here to Skip to main content
15,917,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.).
Posted
Updated 13-Jan-14 8:31am
v6

If you know it well, use MATLAB and see if it's fast enough. If it's not fast enough rewrite the lot using a decent physics library in C++.
 
Share this answer
 
Comments
Member 10486344 13-Jan-14 10:43am    
why not java?
Andreas Gieriet 13-Jan-14 11:02am    
There is much debate about speed between C/C++ and C#/Java.
The only naswer: measure it for your application and your programming skills.
Cheers
Andi
CPallini 25-Jan-14 16:06pm    
Yes, there is a such a debate about speed: C vs C++, and C# vs Java. :-D
If I had a spec out there to design a system that required a calculation to run for more than a couple hours, I would reject anything that depended on a single machine.

Aside from computers needing to be periodically restarted, there are things like power failures, equipment failures, janitors hitting the power plugs, etc.

This would be a great candidate for distributed computing. You dole out slices of work to agents, and when these agents complete the work they send it back to a management system that puts them together. This way if an agent fails, only that unit of work is lost and can be redistributed to another agent. You can also easily scale your system so that even if something were to take years on a single machine, could take hours on a distributed system.

If you have such a problem that needs solving, I would look at doing it that way, there are frameworks out there and even systems that have computers available to do the work (SETI@Home uses one such network that is open).
 
Share this answer
 
Comments
[no name] 13-Jan-14 12:25pm    
Reading your answer the first time, I thought it is only overkill. After reading it again I had to press 5 ;)
Ron Beyer 13-Jan-14 13:10pm    
Thanks, this shouldn't be a question about speed, but distribution of work units. With a properly distributed system, speed of a single "agent" becomes irrelevant, even slow code can execute quickly broken into enough (parallel) pieces. That's where the effort should be focused in large set problems.
Member 10486344 13-Jan-14 14:13pm    
Dear Ron, you are right and I knew that but my question is other thing.
Ron Beyer 13-Jan-14 14:14pm    
C++, Java, C#, Visual Basic (.NET), and Matlab all have similar performance in the hands of a competent developer.
Member 10486344 13-Jan-14 14:17pm    
not I, but many persons don't accept this view. difference is present and shows itself very sensible in large programs.
Although there are some guideline, you have to evaluate for each problem its complexity and which langage is appropriate.

Some tricks:

1) For long processing, the first thing to ensure is that an efficient algorithm is used.

2) If the data is too big to fit in memory, then you have to ensure that the algorithm minimize disk access as they are a a few order of magnitude slower that memory access.

3) You have to ensure that selected language is efficient enough. For long processing, compiled language should be typically much faster.

4) Determine at which point computation can be executed in parallels and then used multiple thread or processor if possible.

5) Profile the code with a smaller problem and optimize part that are a bottleneck and then repeat with larger data.

6) Ease of programming might also enter into consideration. A language might be twice as slow (for a given problem of a given size) than another but it take much less developement.

7) For complex problem, sytem capacity like memory usage might need to be taken into consideration as some language allows more efficient memory usage.
 
Share this answer
 
Comments
CPallini 25-Jan-14 16:07pm    
5.
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++.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900