Repository: pytorch
Issue: conda package _openmp_mutex  makes pytorch dataloader slower when set num_workers > 0
Labels: module: binaries,triaged

### 🐛 Describe the bug




I'm using conda 22.11.1 on Ubuntu,  when I install only pytorch 1.13 using this command, the pytorch dataloader works fine:

```
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia
```
results:
```
num_workers=0: Performance metrics: 66.62973213195801s
num_workers=4: Performance metrics: 18.59693670272827s
```

However, when I further install openslide using conda:
```
conda install -c conda-forge openslide
```

The pytorch dataloader is slower when I set num_workers=4
results:
```
num_workers=0: Performance metrics: 70.44163846969604s
num_workers=4: Performance metrics: 79.95612025260925s
```
Aftering debugging, I've found that when I installing openslide package, conda automatically replace package `_openmp_mutex ` version: `4.5`  build: `2_gnu` to `_openmp_mutex`  version: `4.5`  build: `2_kmp_llvm` ,  build  `2_kmp_llvm` is the reason why my dataloader is slower.
I replace my `_openmp_mutex` to the orginal one using:
```
conda install -c conda-forge _openmp_mutex=4.5=2_gnu
```
Everything is back to normal:
results:
```
num_workers=0: Performance metrics: 67.68908190727234s
num_workers=4: Performance metrics: 18.52177381515503s
```




The pytorch dataloader benchmark script
```
import os

from torch.utils.data import DataLoader
from torch.utils.data import Dataset
from PIL import Image
import logging
import time

logging.basicConfig(filename='xxn_performance_log.txt', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

data_dir = '/data/ssd1/by/folowler'  # flower102 dataset


file_names = os.listdir(data_dir)
file_paths = [os.path.join(data_dir, file_name) for file_name in file_names]

import time
class ImageDataset(Dataset):
    def __init__(self, file_paths, transform=None):
        self.file_paths = file_paths
        self.transform = transform


    def __len__(self):
        return len(self.file_paths)

    def __getitem__(self, idx):
        img_path = self.file_paths[idx]

        image = Image.open(img_path).convert('RGB')

        return image

dataset = ImageDataset(file_paths=file_paths)

num_workers_list = [0, 4]

for num_workers in num_workers_list:

    logging.info(num_workers)
    start_time = time.time()

    data_loader = DataLoader(dataset=dataset, batch_size=64, shuffle=True, num_workers=num_workers)

    for batch in data_loader:
           pass

    end_time = time.time()
    print(f"num_workers={num_workers}: Performance metrics: "+str(end_time-start_time))
    logging.info(end_time-start_time)

```


### Versions

Collecting environment information...
PyTorch version: 1.13.1
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.3 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.35

Python version: 3.8.18 (default, Sep 11 2023, 13:40:15)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-6.2.0-34-generic-x86_64-with-glibc2.17
Is CUDA available: False
CUDA runtime version: 11.7.99
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: 
GPU 0: NVIDIA GeForce RTX 3090
GPU 1: NVIDIA GeForce RTX 3090
GPU 2: NVIDIA GeForce RTX 3090
GPU 3: NVIDIA GeForce RTX 3090

Nvidia driver version: 525.125.06
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
架构：                              x86_64
CPU 运行模式：                      32-bit, 64-bit
Address sizes:                      46 bits physical, 48 bits virtual
字节序：                            Little Endian
CPU:                                16
在线 CPU 列表：                     0-15
厂商 ID：                           GenuineIntel
型号名称：                          Intel(R) Xeon(R) Gold 5222 CPU @ 3.80GHz
CPU 系列：                          6
型号：                              85
每个核的线程数：                    2
每个座的核数：                      4
座：                                2
步进：                              7
CPU 最大 MHz：                      3900.0000
CPU 最小 MHz：                      1200.0000
BogoMIPS：                          7600.00
标记：                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts pku ospke avx512_vnni md_clear flush_l1d arch_capabilities
虚拟化：                            VT-x
L1d 缓存：                          256 KiB (8 instances)
L1i 缓存：                          256 KiB (8 instances)
L2 缓存：                           8 MiB (8 instances)
L3 缓存：                           33 MiB (2 instances)
NUMA 节点：                         2
NUMA 节点0 CPU：                    0-3,8-11
NUMA 节点1 CPU：                    4-7,12-15
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit:        KVM: Mitigation: VMX disabled
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:             Mitigation; Enhanced IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Mitigation; TSX disabled

Versions of relevant libraries:
[pip3] numpy==1.24.3
[pip3] torch==1.13.1
[pip3] torchaudio==0.13.1
[pip3] torchvision==0.14.1
[conda] blas                      1.0                         mkl  
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] mkl                       2023.1.0         h213fc3f_46344  
[conda] mkl-service               2.4.0            py38h5eee18b_1  
[conda] mkl_fft                   1.3.8            py38h5eee18b_0  
[conda] mkl_random                1.2.4            py38hdb19cb5_0  
[conda] numpy                     1.24.3           py38hf6e8229_1  
[conda] numpy-base                1.24.3           py38h060ed82_1  
[conda] pytorch                   1.13.1              py3.8_cpu_0    pytorch
[conda] pytorch-mutex             1.0                         cpu    pytorch
[conda] torchaudio                0.13.1                 py38_cpu    pytorch
[conda] torchvision               0.14.1                 py38_cpu    pytorch

cc @seemethere @malfet @osalpekar @atalman