New Issue: 'here.runningTasks()' doesn't seem to respect 'serial' statements

17562, "bradcray", "'here.runningTasks()' doesn't seem to respect 'serial' statements", "2021-04-12T19:16:23Z"

Summary of Problem

While working with @strikeraryu on a recursive parallel algorithm, we're finding that here.runningTasks() seems to be giving the wrong value when used within a serial block. Specifically, it seems to count the number of tasks created rather than the number that are concurrently executing. This is problematic because it means that the idiom we usually advertise for throttling parallelism:

serial here.runningTasks() >= here.numCores() { ... }

doesn't necessarily work as intended because the number of running tasks will always be over-counted.

Steps to Reproduce

Source Code:

Here's a simple program that demonstrates this:

serial true {
  cobegin {
    writeln(here.runningTasks());
    writeln("1");
    writeln("2");
    writeln("3");
  }
}

On my 4-core system, I'm seeing here.runningTasks() always print as 4, and the other three writeln()s seem to always appear in sequence. Whereas if I remove the cobegin, I see the number of running tasks as 1, and if I remove the serial, I see the output emerge in random orders as expected. This suggests to me that the serial is working as intended, but that the accounting for the number of running tasks is incorrect.

Compile command:
chpl testit.chpl

./testit

Configuration Information

  • Output of chpl --version: chpl version 1.25.0 pre-release (d54a88a62f)
  • Output of $CHPL_HOME/util/printchplenv --anonymize:
CHPL_TARGET_PLATFORM: darwin
CHPL_TARGET_COMPILER: clang
CHPL_TARGET_ARCH: x86_64
CHPL_TARGET_CPU: native
CHPL_LOCALE_MODEL: flat
CHPL_COMM: none
CHPL_TASKS: qthreads
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: system *
CHPL_MEM: jemalloc
CHPL_ATOMICS: cstdlib
CHPL_GMP: bundled
CHPL_HWLOC: bundled
CHPL_REGEXP: re2
CHPL_LLVM: none *
CHPL_AUX_FILESYS: none
1 Like