Python multiprocessing is slow on slurm

I’m using Python multiprocessing and then submitting the job with sbatch. The .sh code is as follows:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#!/bin/bash
##----------------------- Start job description -----------------------
#SBATCH --partition=standard
#SBATCH --job-name=multi_Leaspy
#SBATCH --nodes=1
#SBATCH --ntasks=40
#SBATCH --mem-per-cpu=4096
#SBATCH --time=160:00:00
#SBATCH --mail-type=ALL
#SBATCH --output=out-%j.log
#SBATCH --error=err-%j.log
##------------------------ End job description ------------------------
</code>
<code>#!/bin/bash ##----------------------- Start job description ----------------------- #SBATCH --partition=standard #SBATCH --job-name=multi_Leaspy #SBATCH --nodes=1 #SBATCH --ntasks=40 #SBATCH --mem-per-cpu=4096 #SBATCH --time=160:00:00 #SBATCH --mail-type=ALL #SBATCH --output=out-%j.log #SBATCH --error=err-%j.log ##------------------------ End job description ------------------------ </code>
#!/bin/bash
##----------------------- Start job description ----------------------- 
#SBATCH --partition=standard
#SBATCH --job-name=multi_Leaspy
#SBATCH --nodes=1
#SBATCH --ntasks=40
#SBATCH --mem-per-cpu=4096
#SBATCH --time=160:00:00
#SBATCH --mail-type=ALL
#SBATCH --output=out-%j.log
#SBATCH --error=err-%j.log
##------------------------ End job description ------------------------ 

This is the snippet where i parallelize the code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>num_workers = ntasks = int(os.environ.get('SLURM_NTASKS', 1))
if __name__ == "__main__":
with ProcessPoolExecutor(max_workers = num_workers - 1) as executor:
arg_list = [(i, row, df_test, id_test, btstrp, classes, classes_auc,
results_table, MAE_table, features_set, vector_range) for i, row in feat_sub.iterrows()]
for result, MAE_row in executor.map(multiLeaspyIter, arg_list):
if result is not None and MAE_row is not None:
results_table = results_table.append(result, ignore_index=True)
MAE_table = MAE_table.append(MAE_row, ignore_index = True)
</code>
<code>num_workers = ntasks = int(os.environ.get('SLURM_NTASKS', 1)) if __name__ == "__main__": with ProcessPoolExecutor(max_workers = num_workers - 1) as executor: arg_list = [(i, row, df_test, id_test, btstrp, classes, classes_auc, results_table, MAE_table, features_set, vector_range) for i, row in feat_sub.iterrows()] for result, MAE_row in executor.map(multiLeaspyIter, arg_list): if result is not None and MAE_row is not None: results_table = results_table.append(result, ignore_index=True) MAE_table = MAE_table.append(MAE_row, ignore_index = True) </code>
num_workers = ntasks = int(os.environ.get('SLURM_NTASKS', 1))
if __name__ == "__main__":
        with ProcessPoolExecutor(max_workers = num_workers - 1) as executor:       
            arg_list = [(i, row, df_test, id_test, btstrp, classes, classes_auc, 
                      results_table, MAE_table, features_set, vector_range) for i, row in feat_sub.iterrows()]
            for result, MAE_row in executor.map(multiLeaspyIter, arg_list):
                if result is not None and MAE_row is not None:
                    results_table = results_table.append(result, ignore_index=True)
                    MAE_table = MAE_table.append(MAE_row, ignore_index = True)

Then, i ssh and htop to see the resource utilization and there are more executing processes than requested. Furthermore, many waiting processes appear, slowing down everything.

htop results:

Tasks = 1627, 501 thr, 40 running
Load average = 201.3, 180.94, 117.36

Each node has 40 cpus, hyper-threading enabled.

Previously, i was using ProcessPoolExecutor, same code, and it was far slower.

I’m not sure whether multiprocessing is appropiate for a slurm environment or i’m missing something.

Previously, i was using ProcessPoolExecutor, same code, and it was slower.

When i configure the .sh so –ntasks = 1 and the .py so max_workers = 1, the code runs faster. If –ntasks = 5 and max_workers = 5, it goes slower and creates aditional waiting processes.

Apart from that, i noticed with just 1 process, many threads are created.

I’ve tried the same code on Windows and it goes faster.

New contributor

user26458368 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật