Are there C++ developers here?

Hi all,

Wanted to ask if there are C++ developers in the Makerspace. I’ve got some questions on parallelisation and HPC in general. It would be good to get the thoughts of someone with some experience.

Ask away… I am a C++ developer during the working day (and often afterwards)

2 Likes

So I’ve been working for severals years on a C code which makes simulations for geomechanics. I’d like to parallelise the code and rewrite it in C++ (its a code from the 90s).

I’ve got no idea where to start and which toolkits could be used for CPU or GPU parallelisation. I am ideally looking for professionals that can advise me on what to do.

Do you have some advice/recommendations?

GPU it’s complicated, you probably want to look into Vulkan APi

For CPU it’s easy, reduce the code that needed to be parallelized into an object and just spin a new thread and use a vector with some semaphore to exchange data

I haven’t kept up with the standards but my understanding is that compute is a minor part of Vulkan and it’s still primarily for 3D workloads?

I have very little experience but we’ve used OpenCL and CUDA and ended up with CUDA because the documentation is better, more prolific and still seems to be a tad more optimized. The CUDA tutorials out there cover a lot of numerical applications that you should find familiar.

2 Likes

Also, from C++ 17, if you have a few simple loops that can be parallelized, then there is now stuff like:

std::vector<std::string> foo;
std::for_each(
    std::execution::par, // This sets the loop to be executed in parallel as best the OS can do.
    foo.begin(),
    foo.end(),
    [](auto&& item)
    {
        //do stuff with item
    });

(Stolen from stack overflow)

However, starting a thread has an inherent overhead, so really only worth it for long-lasting computations (here quantifying “long lasting” and “trade-off” will be very per-casis dependent)

3 Likes

Thanks. Nice to know that its native to C++ now.

Yes for CUDA I know a lot of softwares in my branch that have started using it. Its a bit hard for me to tell if I’d really need GPUs or if the performance I get from CPUs would be enough. I’ll probably start with CPU first and see

1 Like

I think the best strategy for me is to try to find someone to write my new C++ architecture

Do you guys have any tips for finding a company/contractor that can do that at a reasonable price?

1 Like

I didn’t realized he wanted to use compute units, silly me :slight_smile:

1 Like

CUDA is fine if you don’t mind being NVIDIA-only and losing support for AMD.
Vulkan is very complex and trying to write truly portable Vulkan code seems to be a challenge; it’s up to you to check that you comply to the restrictions of the user’s driver, and it’s quite easy to do something that breaks that without knowing. The validation layer is helpful to ensure correctness though.
There’s also OpenGL and DirectX. I find DirectX11 the easiest to work with (maybe from familiarity) but of course you’re restricted to Windows (unless you use some sort of emulation layer, which exists but I have no experience there)
There’s also SIMD support. Some compilers (LLVM for one?) can autovectorize if the code is simple enough, and that can give you a good speedup even with a single thread. Otherwise you are stuck using intrinsics which are a pain, or vector extensions (compiler-specific I think)
LLVM also has a thread sanitizer which is very helpful for finding race conditions in threaded software.

2 Likes

I really have to get into LLVM

Your approach is for sure valid (and for CPU look into Intel MKL by the way).

However, one simple heuristic whether a GPU will be better is the more threads you’ll need, the better the GPU will be. That’s something you’ll only figure out once you lay out the math for threading.

I meant Clang not LLVM, sorry

1 Like