|
|
|
|
|
by dragontamer
1501 days ago
|
|
OpenMP can parellize a for loop like: #pragma openmp parallel for
for(int i=0; i<1000000; i++)
C[i] = A[i] + B[i];
It's normal C++ and the pragma auto-parallelizes the loop. It's actually really easy and convenient.OpenMP is probably the easiest join/fork model of parallelism on any C++ system I've used. It doesn't always get the best utilization of your CPU cores, but it's really, really simple. It's the best way to start IMO, far easier than std::thread, or switching to functional style for other libraries. Just write the same code as before but with a few #pragma omp statements here and there. |
|
C++ is an ISO standard, you can use it _everywhere_, in space, in automotive, in aviation, in trains, in medical devices, _everywhere_.
OpenMP is not C++, it is a different programming language than C++.
OpenMP is not an ISO standard, you can't use it in _most_ domains that you can use C++.
Your example:
shows how bad OpenMP is.It does not run in parallel on GPUs or on FPGAS (lacking target offload directives), and you can't use it on most domains in which you can use C++.
The following is ISO standard C++:
it runs in _parallel_ EVERYWHERE: GPUs, CPUs, FPGAS, and it is certified for all domains for which C++ is (that is: all domains).Show me how to sort an array in parallel on _ANY_ hardware (CPUs, GPUs, FPGAs) with OpenMP. With C++ is as simple as:
If you have a GPU, this offloads to the GPU. If you have an FPGA, this offloads to the FPGA. If you have a CPU with 200 cores, this uses those 200 cores.There is no need to turn your ISO C++ compliant program or libraries into OpenMP. That prevents them from being used by many domains on which C++ runs on. It also adds an external dependency for parallelism, for no good reason.
For any problem that OpenMP can solve, OpenMP is _always_ a worse solution than just using strictly ISO standard and compliant C++.
OpenMP has completely lost a reason to exist. It's not 1990 anymore.