(Re)Starting with C++ (for scientific computing)
Asked Answered
O

5

16

I have a fair hang of programming in various languages. I have been implementing my codes for research using MATLAB (during the past few months) and for the first time really noticed the difference in execution speed of MATLAB v$ C. (As much as I love the blazingly fast prototyping capabilities).

I am looking to pickup C++ and start using it in my research. I am aware of OOP and have programmed fair bit of Java (relatively long back) and C++ (even longer back). I would like to really get deep into C++ now and hence need suggestions for resources on the same:

  • What C++ things I need to pick up (STLs and. ) to really make good use of C++?
  • What is a good tutorial/manual to get started with?
  • What are the numerical/scientific libraries for C++? GSL? Is there a equivalent (features) of Scipy/Numpy for C++?

I shall be programming on Linux, so I shall be using g++ .

Any pointers to previous SO questions also appreciated.

Oogonium answered 25/11, 2010 at 23:3 Comment(1)
You'd probably get much better answers if you described what kinds of algorithms and data structures you'll be using. Is it just numbers or are you doing symbolic computations as well? Are you doing linear algebra, FFTs, wavelets etc.?Romito
U
7

You'll want to get to grips with parallel programming as quickly as possible. For message-passing I like this book by Karniadakis and Kirby. Of the books on OpenMP, for distributed-memory programming, this one is the best.

If you can get access to them, then Intel's Threading Building Blocks, Maths Kernel Library, and Integrated Performance Primitives are good to have. If not, there are plenty of open source alternatives, start looking at Netlib.

Oh, I almost forgot BOOST, which is a must.

Unguarded answered 25/11, 2010 at 23:14 Comment(5)
He's just getting into C++. Your approach is going to leave him never having resolved his memory leaks before he starts creating race conditions.Incoercible
@xscott: that's as may be, but if someone is worried about high-performance scientific computing, at some point soon they are going to need to actually use all the cores on their machine, rather than running at 50% or 25% speed. fork() is probably worth a try before threading, though.Mimesis
Mark's right - better to get parallelism in at the start. If he waits, as @Josh suggests, to be regularly using dynamic bindings before starting on parallelism, he'll be writing very sophisticated, `powerful', serial code on his 32-core laptop. @Amit, I agree with recommendations for BOOST, STL, K&K, OpenMP. While cautiously optimistic about Intel's TBB & IPP, I wouldn't write any code I wanted to have working 7+ years from now with either of them just yet. Most crucially of all, remember that it's about solving your problem in a scalable, maintainable way. Anything else is a hobby.Yonah
@Jonathan Dursi: you put it better than I could. @Incoercible seems to have missed the bit where @Amit explains that he's not new to C++, but then so does @Amit.Unguarded
@Incoercible +1 but that is inevitable in C++.Romito
I
5

In regards to numerical stuff like Numpy, you should have a look at both:

Blitz++ http://www.oonumerics.org/blitz/

and

Jama/TNT http://math.nist.gov/tnt/download.html

Incoercible answered 25/11, 2010 at 23:12 Comment(0)
D
4

On the library side, check out Armadillo. It almost gives you the full extent of MATLAB's array manipulation syntax and uses LAPACK and BLAS (ATLAS) under the hood.

Dabber answered 29/11, 2010 at 7:8 Comment(1)
Also suggested is the MLPACK library, which is a fast machine learning library (classification, regression, clustering, etc) built on top of ArmadilloSpadix
M
2

This tutorial absolutely rocks, but you may not want to tackle it initially.

http://www.parashift.com/c++-faq/

Make sure to read up on the STL (standard template library) and other stuff, using sites like:

http://cplusplus.com/

And, check out the Boost library:

http://www.boost.org/

To make really good use of C++, you need to learn at least the STL, that alone will save you lots of time, but as parashift mentions, C++ OOP is only programming with objects, if you don't use dynamic bindings.

Mycorrhiza answered 25/11, 2010 at 23:15 Comment(3)
You make it sound like there's something wrong with "only programming with objects" (or functions, templates etc). Utility of dynamic binding's indicated by need to determine the type/class for inputs at run type - more the exception than the norm in many fields.Suspensoid
I'm not saying that there is anything wrong with using just objects. I'm just saying the real power comes into play when you have a collection of base class pointers, etc. Here is the part I was referring to (I think, just glanced), but it goes over why virtual / dynamic bindings are so important: parashift.com/c++-faq/virtual-functions.html But no, I wasn't trying to imply that it was bad.Mycorrhiza
Interesting perspective... for my mind - the "real" power of C++ comes into play when you can use compile time polymorphism (or don't need any), and runtime polymorphism is just the best (usually) in an awkward situation (which is always welcome, but unexciting). Anyway... no worries :-).Suspensoid
G
-2

TRNG is a parallel random number generation library. It allows you to create multiple independent streams and was designed for use on clusters.

Geomancer answered 10/8, 2013 at 18:37 Comment(1)
This doesn't add anything useful.Unguarded

© 2022 - 2024 — McMap. All rights reserved.