I want to run this program :
#include <iostream>
#include <omp.h>
using namespace std;
int main()
{
int numThread, myId;
cout << "num_procs=" << omp_get_num_procs();
omp_set_num_threads(omp_get_num_procs());
#pragma omp parallel
{
cout << "\nid=" << omp_get_thread_num();
numThread = omp_get_num_threads();
cout << "\nmax-thread=" << omp_get_max_threads();
}
getchar();
}
The result is:
num_procs=4
id=0
max-thread=4
I think this result must be repeat and print 4 times but I don't know why it prints only one time.
I run below code from this comment in this post and my result is different.
#include <iostream>
#include <omp.h>
int main(int argc, const char * argv[])
{
int nProcessors = omp_get_max_threads();
std::cout << nProcessors << std::endl;
omp_set_num_threads(nProcessors);
std::cout << omp_get_num_threads() << std::endl;
#pragma omp parallel for
for (int i = 0; i<5; i++){
int tid = omp_get_thread_num();
std::cout << tid << "\t tid" << std::endl;
int nThreads = omp_get_num_threads();
std::cout << nThreads << "\t nThreads" << std::endl;
}
exit(0);
}
print this result :
4
1
0 tid
1 nThreads
0 tid
1 nThreads
0 tid
1 nThreads
0 tid
1 nThreads
0 tid
1 nThreads
I run this command in cmd :
set OMP_NUM_THREADS=16
and when i run :
set OMP_NUM_THREADS in cmd
print this result: OMP_NUM_THREADS=16
but when I close cmd and reopen it and run set OMP_NUM_THREADS print this result:
Environment variable OMP_NUM_THREADS not defined !!!!!!!!Please Help me.