简体   繁体   中英

Is there a way to compile multi-threaded C++ program with single-threaded version library?

I am trying to do a code auto-complile and auto-evaluaton program. I want to compare a program's efficiency difference in multi-threaded mode and single-threaded mode. So I am wonder that if there is a compiling option that allows me to compile a multi-threaded program with a psudo-multithread library (which uses actually single threaded implementation) to derive a single-threaded program from the multi-threaded one.

I don't know what you use for multi threading but you could use OpenMP a shared memory multiprocessing API for that.

You have two ways of switching between multi-threaded mode and single-threaded mode :

  • Disable/enable OpenMP with the -fopenmp flag in GCC and Clang.
  • Use OMP_NUM_THREADS=X environment variable or directly use the routine set_omp_num_threads(X) where X is your thread numbers.

Note that there is a difference between the two ways they are not equivalent. I can detail this point if needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM