简体   繁体   中英

Combining MPI with c++11 and CUDA

I am writing a molecular dynamics simulation and some kernels will be computed with CUDA. I started my code with a plain CPU implementation utilizing some c++11 features. Now that I have to add some CUDA code I have to use compilers that don't support c++11 features (gcc <= 4.6).

In my makefile I am creating objects from all cpp-files separately and linking them all together in the end. Furthermore my code is split up in a way that it would be possible to compile parts without CUDA with a "modern" compiler and the rest (utilizing CUDA) with an older compiler.

My question now is, if this is okay or if I would/could run into problems with this way?

I don't know about Cuda, but what I know is that linking C++98 and C++11 object files together is highly dangerous because template instantiations are emitted only once into the final executable. The point is, that the ABI might have changed.

I've once run into this issue with std::complex<double>::real() and g++. One of the two instantiations returned a pointer to a double , the other the double istelf. The linker emitted only one of the two instantiations (the one returning doubles directly) into the final executable and the calling C++98-code subsequently mistook doubles as pointers, resulting in a segfault.

For why this happened, just have a look into <complex> : Depending on wheter __cplusplus >= 201103L or not, real() is either declared this way:

constexpr _Tp real();

or this way:

const _Tp& real() const { return _M_real; }

I doubt that there are more examples than just std::complex around.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM