Setting number of threads at runtime

Open discussion regarding features, bugs, issues, vendors, etc.

Setting number of threads at runtime

Postby niklasfi » Wed Jul 31, 2013 10:13 am

Hello,

I am trying to set the number of threads to be used by LAPACK at runtime. The documentation says this can be done by setting OMP_NUM_THREADS which I have (unsuccessfully) tried. Here is some sample code:

Code: Select all
void scpl_bxinv(FileRepresentation* input, FileRepresentation* result)
{
    uint32_t m;

        omp_set_num_threads(4);
        openblas_set_num_threads(4);
        setenv("OMP_NUM_THREADS", "4", 1);

    for(m = 0; m < input->info->matrix_count; ++m){
        int num_eigenvectors;
        int* ifail = malloc(sizeof(int) * input->head[m].size);
        LAPACKE_dstevx(
                LAPACK_COL_MAJOR, //int matrix_order,
                'V', //char jobz,
                'A', //char range,
                input->head[m].size, //lapack_int n,
                input->body + input->head[m].offset, //double* d,
                input->body + input->head[m].offset + input->head[m].size, //double* e,
                0., //double vl,
                0., //double vu,
                0, //lapack_int il,
                0, //lapack_int iu,
                0, //double abstol,
                &num_eigenvectors, //lapack_int* m,
                result->body + result->head[m].offset + result->head[m].size * result->head[m].size, //double* w,
                result->body + result->head[m].offset, //double* z,
                input->head[m].size,//lapack_int ldz,
                ifail //lapack_int* ifail
        );

        assert(num_eigenvectors == input->head[m].size);

        free(ifail);
    }
}


If I run this, however only a single thread is busy on my machine. OpenBLAS was compiled with "NO_AFFINITY=1 USE_OPENMP=1" and stated the following after finishing to compile.

Code: Select all
 OpenBLAS build complete.

  OS               ... Linux             
  Architecture     ... x86_64               
  BINARY           ... 64bit                 
  C compiler       ... GCC  (command line : gcc)
  Fortran compiler ... GFORTRAN  (command line : gfortran)
  Library Name     ... libopenblas_sandybridgep-r0.2.6.a (Multi threaded; Max num-threads is 4)

 Use OpenMP in the multithreading. Becasue of ignoring OPENBLAS_NUM_THREADS and GOTO_NUM_THREADS flags,
 you should use OMP_NUM_THREADS environment variable to control the number of threads.


I need to set the number of threads at runtime, since my experiment is about altering the number of threads working on a problem. Is it better to solve multiple problems in parallel, or a single problem with a parallel library?

Greetings,
Niklas
niklasfi
 
Posts: 2
Joined: Thu Jul 25, 2013 10:41 am

Return to User Discussion

Who is online

Users browsing this forum: No registered users and 1 guest