You are not logged in.

#1 2020-09-08 20:06:10

wkg
Member
Registered: 2020-09-08
Posts: 2

C++, OpenMP spawns multiple threads but only runs on one logical core

Program using OpenMP will spawn multiple processes (seen in htop) but only utilizes one logical core. Not sure what is going on here, this works fine on a couple Debian based systems.

Using CMake, some relevant lines from CMakeLists:

set(CMAKE_CXX_FLAGS "-O3 -DBOOST_LOG_DYN_LINK -fopenmp")

find_package(OpenMP)
if(Open_MP_CXX_FOUND)
	target_link_libraries(MyTarget PUBLIC OpenMP::OpenMP_CXX)
endif()

The OpenMP usage is dead simple, just a single

#pragma omp parallel for

over a vector.

I tried setting some environmental variables based on others' suggestions, here is what I've tried:

$ echo $GOMP_CPU_AFFINITY
0 1 2 3 4 5 6 7
$ echo $OMP_NUM_THREADS
8
$ echo $OMP_PROC_BIND
true

Offline

#2 2020-09-09 15:57:47

fistrosan
Member
Registered: 2020-04-01
Posts: 171

Re: C++, OpenMP spawns multiple threads but only runs on one logical core

This belongs more to stackoverflow, but hey, let us try. I am surprised about the syntax in C++. In fortran you need to declare private and shared variables (after all openMP is for share memory) as well as the number of threads you want to use. It would go something like this:

$OMP PARALLEL PRIVATE(private variables), SHARED(shared variables), NUM_THREADS(number of threads)
$OMP DO SCHEDULE (static or dynamic)
DO
whatever
ENDDO
$OMP END PARALLEL

Offline

#3 2020-09-09 17:39:02

wkg
Member
Registered: 2020-09-08
Posts: 2

Re: C++, OpenMP spawns multiple threads but only runs on one logical core

Yeah, it's a little different with C++ but similar, and quite easy to use. To be honest I would prefer not to use it, but I was pushed to use it by a professor in the group, although it may get rewritten at some point.

The reason I posted here is because my issue is Arch specific. Everything works as expected on other distros. I suspect that I am missing something quite simple here.

Offline

#4 2020-09-09 17:46:13

fistrosan
Member
Registered: 2020-04-01
Posts: 171

Re: C++, OpenMP spawns multiple threads but only runs on one logical core

I see. Well I am running arch and openMP with fortran90 and it can use all of my cpus, so I am not sure about being arch specific ... just out of curiosity: is the loop you are trying to parallelize nested within a loop that is already parallelized ? In that case you should do:

setenv OMP_NESTED true

Otherwise it will not run in parallel even if your C++ syntax is flawless.

Offline

Board footer

Powered by FluxBB