2

I am planning to use pure C MPI library in C++ application, I don't want to add unnecessary bloat by running eg. Boost MPI layer that wraps all stuff in the MPI::<func> classes.

Is there anything I should be aware of?

jalf
  • 243,077
  • 51
  • 345
  • 550
M_1
  • 2,135
  • 4
  • 21
  • 24
  • there's not likely to be any real bloat. MPI contains plenty of overhead (any cross-process, and especially cross-system API does), and wrapping the API in sensible C++ idioms is not going to make a measurable difference. It is entirely possible that the Boost wrappers are *literally* zero-overhead, for such is the magic of inlining. ;) – jalf Nov 06 '10 at 20:16

2 Answers2

8

You should wrap all your includes for C-headers in an extern "C" block in order to avoid problems with the name mangling of C++ compilers.

extern "C" {
    // include C-headers
}

Read more here.

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
2

Not really, as most libraries are prepared to be included in a C++ compiler (if not, you can do as Space Cowboy above suggests). However, I would advice you (if you don't mind) on reconsidering boost MPI. It doesn't add unnecessary bloat, and gives you a more comprehensive interface to MPI in an object-oriented environment. It adds more semantics to types being transferred via MPI, and even gives you more "functional" operators, such as using functors for the calculation operations (e.g. reduce), etc. The ammount of code they add is negligible, and most of the time, there is no run-time overhead, as abstractions are implemented via template metaprogramming.

Diego Sevilla
  • 28,636
  • 4
  • 59
  • 87
  • I also considered templates, but I'm not really convinced how this would play with MPI datatypes. Additionally templates makes my head hurt because of the cryptoerrors as I call them. – M_1 Nov 06 '10 at 18:58
  • I see... In the case of boost.MPI, the templates are given for you to use, so not so different to use than, say, a `vector`... – Diego Sevilla Nov 06 '10 at 19:12