Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU core duplication in OpenMPI 5.0.5 when running multiple tasks #12884

Open
lemon3242 opened this issue Oct 26, 2024 · 4 comments
Open

CPU core duplication in OpenMPI 5.0.5 when running multiple tasks #12884

lemon3242 opened this issue Oct 26, 2024 · 4 comments

Comments

@lemon3242
Copy link

lemon3242 commented Oct 26, 2024

Hi all,

I encountered an issue with OpenMPI 5.0.5 on my system where multiple MPI tasks are being assigned to the same CPU cores, even though I expect distinct cores for different programs. This issue occurs when running two separate MPI jobs concurrently. Here are the details:

Operating System: Ubuntu 22.04
CPU: Dual AMD EPYC 9754

The first program assigns 64 MPI ranks, and the --report-bindings output shows the correct assignment of cores. However, when I run a second program while the first one is still running, MPI assigns the same cores to the second program, resulting in core overlap and suboptimal CPU usage.

First Program Command and Output

$ mpirun --report-bindings -np 64 python ./xxx1.py
[ytgroup-epyc9754:1162290] Rank 0 bound to package[0][core:0]
[ytgroup-epyc9754:1162290] Rank 1 bound to package[0][core:1]
[ytgroup-epyc9754:1162290] Rank 2 bound to package[0][core:2]
[ytgroup-epyc9754:1162290] Rank 3 bound to package[0][core:3]
[ytgroup-epyc9754:1162290] Rank 4 bound to package[0][core:4]
[ytgroup-epyc9754:1162290] Rank 5 bound to package[0][core:5]
[ytgroup-epyc9754:1162290] Rank 6 bound to package[0][core:6]
[ytgroup-epyc9754:1162290] Rank 7 bound to package[0][core:7]
[ytgroup-epyc9754:1162290] Rank 8 bound to package[0][core:8]
[ytgroup-epyc9754:1162290] Rank 9 bound to package[0][core:9]
[ytgroup-epyc9754:1162290] Rank 10 bound to package[0][core:10]
[ytgroup-epyc9754:1162290] Rank 11 bound to package[0][core:11]
...
[ytgroup-epyc9754:1162290] Rank 63 bound to package[0][core:63]

Second Program Command and Output

When I start the second program using the following command:

$ mpirun --report-bindings -np 27 python ./xxx2.py

The second program is assigned to the same cores that the first program is already using, causing core overlap:

[ytgroup-epyc9754:1162897] Rank 0 bound to package[0][core:0]
[ytgroup-epyc9754:1162897] Rank 1 bound to package[0][core:1]
[ytgroup-epyc9754:1162897] Rank 2 bound to package[0][core:2]
[ytgroup-epyc9754:1162897] Rank 3 bound to package[0][core:3]
[ytgroup-epyc9754:1162897] Rank 4 bound to package[0][core:4]
[ytgroup-epyc9754:1162897] Rank 5 bound to package[0][core:5]
[ytgroup-epyc9754:1162897] Rank 6 bound to package[0][core:6]
[ytgroup-epyc9754:1162897] Rank 7 bound to package[0][core:7]
[ytgroup-epyc9754:1162897] Rank 8 bound to package[0][core:8]
[ytgroup-epyc9754:1162897] Rank 9 bound to package[0][core:9]
...
[ytgroup-epyc9754:1162897] Rank 26 bound to package[0][core:26]

Workaround

For now, I found that using --bind-to none in OpenMPI 5.0.5 can avoid this problem by disabling core binding. However, this is not an optimal solution because it prevents MPI from utilizing core affinity optimally. I would like to know if there is a more appropriate way to correctly assign distinct cores to different programs without completely turning off the binding.

Related Observations

In OpenMPI 4.1.5, I have noticed that hyper-threading is sometimes enabled unexpectedly when running MPI programs. Setting OMP_NUM_THREADS=1 seems to mitigate the issue, but I am unsure if this is related to OpenMPI, or OpenBLAS.

I would greatly appreciate any guidance on how to configure OpenMPI to avoid core duplication between concurrent MPI jobs. Additionally, I am open to suggestions or fixes that could help resolve the hyper-threading issue observed in OpenMPI 4.1.5.

N.

@rhc54
Copy link
Contributor

rhc54 commented Oct 26, 2024

Short answer is - you can't. It is impossible for one mpirun execution to know what another mpirun has done in terms of process placement. They are completely independent jobs.

You have two available solutions:

  1. You can specify a cpu envelope for each mpirun execution. Negative is that you have to manually specify it for each run.
  2. You can use the PRRTE DVM to create a persistent environment and then execute your multiple jobs within it. Because it is persistent and the different jobs are operating within it, the DVM can (and will) separate the resources for the two jobs.

Not sure what you mean about hyper-threading being enabled. That is usually a BIOS issue and has nothing to do with mpirun. Certainly, nothing in OMPI would be influenced by (or even aware of) the setting of OMP_NUM_THREADS.

@lemon3242
Copy link
Author

Hi,

Thank you very much for your attention and answer to this question. Regarding your first suggestion, can I use the '--cpu-set 0-63' option?

$ mpirun --cpu-set 0-63 --bind-to core --report-bindings -np 64 python ./xxx.py
--------------------------------------------------------------------------
There are not enough slots available in the system or not enough
CPUs in the specified PE-LIST to map the number of processes requested
by the application:

  app:  python
  Number of procs: 64
  pe-list: 0-63

Either request fewer procs for your application, make more slots
available for use, or expand the pe-list.

A "slot" is the PRRTE term for an allocatable unit where we can
launch a process.  The number of slots available are defined by the
environment in which PRRTE processes are run:

  1. Hostfile, via "slots=N" clauses (N defaults to number of
     processor cores if not provided)
  2. The --host command line parameter, via a ":N" suffix on the
     hostname (N defaults to 1 if not provided)
  3. Resource manager (e.g., SLURM, PBS/Torque, LSF, etc.)
  4. If none of a hostfile, the --host command line parameter, or an
     RM is present, PRRTE defaults to the number of processor cores

In all the above cases, if you want PRRTE to default to the number
of hardware threads instead of the number of processor cores, use the
--use-hwthread-cpus option.

Alternatively, you can use the --map-by :OVERSUBSCRIBE option to ignore
the number of available slots and size of the pe-list when placing the
processes.
--------------------------------------------------------------------------

I once tried the LSF job management system, and the CPU core task allocation was still duplicated.

This error suggests that OpenMPI is trying to bind 64 processes to cores 0-63, but it is either not recognizing enough "slots" (resource allocation units) or is misinterpreting the core availability. Here’s why this might be happening based on the system information you provided.

$ lscpu
Architecture:             x86_64
  CPU op-mode(s):         32-bit, 64-bit
  Address sizes:          52 bits physical, 57 bits virtual
  Byte Order:             Little Endian
CPU(s):                   256
  On-line CPU(s) list:    0-255
Vendor ID:                AuthenticAMD
  Model name:             AMD EPYC 9754 128-Core Processor
    CPU family:           25
    Model:                160
    Thread(s) per core:   1
    Core(s) per socket:   128
    Socket(s):            2
    Stepping:             2
    Frequency boost:      enabled
    CPU max MHz:          3100.3411
    CPU min MHz:          1500.0000
    BogoMIPS:             4499.79
$ numactl --hardware
available: 2 nodes (0-1)
node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
node 0 size: 386919 MB
node 0 free: 333714 MB
node 1 cpus: 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
node 1 size: 644823 MB
node 1 free: 597174 MB
node distances:
node   0   1
  0:  10  32
  1:  32  10

I am curious why everything works fine when I use openmpi 4.1.5, but openmpi 5.0.5 will repeatedly allocate CPU tasks. I'm a beginner, I don't really understand what's going on here.

Thank you again for your attention.

@rhc54
Copy link
Contributor

rhc54 commented Oct 27, 2024

I fear there is some confusion here - the scenario you originally described (getting an allocation and then executing two parallel mpirun jobs inside it) will always result in reuse of the CPUs, regardless of the OMPI version employed. Your latest comments sound like you are doing something different?

The error you report from using the cpu-set option indicates that you didn't get an allocation of 64 slots from whatever scheduler you are using. You can add --display alloc to the mpirun cmd line to see the allocation we believe we were given.

Note that LSF (if that is what you are using) is causing problems and is only weakly supported at best - IBM is no longer contributing to the project, and none of the developers have access to LSF-based machines for testing or treating bugs. So if the problem is related to LSF, I fear there is little/nothing we can do.

@lemon3242
Copy link
Author

Thanks. I wasn't paying special attention to LSF, though I was worried it was an unexpected problem, so I tried doing it manually in the shell as well as using the LSF system to automatically assign it, and it seemed to be the same result.

Here is the result of running the command with --display alloc

$ mpirun --display alloc --cpu-set 0-63 --bind-to core --report-bindings -np 64 python ./xxx.py

======================   ALLOCATED NODES   ======================
    ytgroup-epyc9754: slots=1 max_slots=0 slots_inuse=0 state=UP
        Flags: DAEMON_LAUNCHED:LOCATION_VERIFIED
        aliases: ytgroup-epyc9754
=================================================================

======================   ALLOCATED NODES   ======================
    ytgroup-epyc9754: slots=256 max_slots=0 slots_inuse=0 state=UP
        Flags: DAEMON_LAUNCHED:LOCATION_VERIFIED:SLOTS_GIVEN
        aliases: ytgroup-epyc9754
=================================================================

======================   ALLOCATED NODES   ======================
    ytgroup-epyc9754: slots=256 max_slots=0 slots_inuse=0 state=UP
        Flags: DAEMON_LAUNCHED:LOCATION_VERIFIED:SLOTS_GIVEN
        aliases: ytgroup-epyc9754
=================================================================
--------------------------------------------------------------------------
There are not enough slots available in the system or not enough
CPUs in the specified PE-LIST to map the number of processes requested
by the application:

  app:  python
  Number of procs: 64
  pe-list: 0-63

Either request fewer procs for your application, make more slots
available for use, or expand the pe-list.

A "slot" is the PRRTE term for an allocatable unit where we can
launch a process.  The number of slots available are defined by the
environment in which PRRTE processes are run:

  1. Hostfile, via "slots=N" clauses (N defaults to number of
     processor cores if not provided)
  2. The --host command line parameter, via a ":N" suffix on the
     hostname (N defaults to 1 if not provided)
  3. Resource manager (e.g., SLURM, PBS/Torque, LSF, etc.)
  4. If none of a hostfile, the --host command line parameter, or an
     RM is present, PRRTE defaults to the number of processor cores

In all the above cases, if you want PRRTE to default to the number
of hardware threads instead of the number of processor cores, use the
--use-hwthread-cpus option.

Alternatively, you can use the --map-by :OVERSUBSCRIBE option to ignore
the number of available slots and size of the pe-list when placing the
processes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants