U
    3dm                     @   sD   d Z ddlZddlZddlZddlZddlmZ dd Zdd ZdS )	z,Helpers for OpenMP support during the build.    N   )compile_test_programc                 C   sR   t | dr| jd } n| jj} tjdkr.dgS tjdkrLdtddkrLg S d	gS )
Ncompilerr   win32z/openmpdarwinZopenmpCPPFLAGS z-fopenmp)hasattrr   	__class____name__sysplatformosgetenv)r    r   G/tmp/pip-unpacked-wheel-zrfo1fqw/sklearn/_build_utils/openmp_helpers.pyget_openmp_flag   s    

r   c            	   
   C   s  dt jkrdS td} t dd}|dk	rH| d}dd |D }t}d}z^t| ||d	}|rd
|d krt	|d  dd }t
||k}ndt jkrd}nd}W n* tk
r } zd}|}W 5 d}~X Y nX |s
t drtd|ntd}t| |S )z6Check whether OpenMP test code can be compiled and runZPYODIDE_PACKAGE_ABIFz        #include <omp.h>
        #include <stdio.h>
        int main(void) {
        #pragma omp parallel
        printf("nthreads=%d\n", omp_get_num_threads());
        return 0;
        }
        LDFLAGSN c                 S   s   g | ]}| d r|qS ))z-Lz
-Wl,-rpathz-lz-Wl,--sysroot=/)
startswith).0flagr   r   r   
<listcomp>?   s   
z(check_openmp_support.<locals>.<listcomp>)extra_preargsextra_postargsz	nthreads=r   =r   ZPYTHON_CROSSENVTZSKLEARN_FAIL_NO_OPENMPz0Failed to build scikit-learn with OpenMP supportas  

                                ***********
                                * WARNING *
                                ***********

                It seems that scikit-learn cannot be built with OpenMP.

                - Make sure you have followed the installation instructions:

                    https://scikit-learn.org/dev/developers/advanced_installation.html

                - If your compiler supports OpenMP but you still see this
                  message, please submit a bug report at:

                    https://github.com/scikit-learn/scikit-learn/issues

                - The build will continue with OpenMP-based parallelism
                  disabled. Note however that some estimators will run in
                  sequential mode instead of leveraging thread-based
                  parallelism.

                                    ***
                )r   environtextwrapdedentr   stripsplitr   r   intlen	Exceptionwarningswarn)	coder   r   Zopenmp_exceptionoutputZnthreadsZopenmp_supported	exceptionmessager   r   r   check_openmp_support(   sP    
  


r*   )	__doc__r   r   r   r$   Zpre_build_helpersr   r   r*   r   r   r   r   <module>   s   