Thread: only one thread shows on openMP code inside

  1. #1
    Registered User
    Join Date
    Feb 2011

    only one thread shows on openMP code inside

    seems I am able to access all the OpenMP functions by just including omp.h.

    Tried running the example:

    #include <omp.h>
    #include <stdio.h>
    #include <stdlib.h>
    int main (int argc, char *argv[]) 
    int nthreads, tid,nproc,nmaxthreads;
      /* Fork a team of threads giving them their own copies of variables */
    #pragma omp parallel num_threads(4) 
      /* Obtain thread number */
      tid = omp_get_thread_num();
      printf("Hello World from thread = %d\n", tid);
      printf("numri maksimal i threadeve eshte = %d\n", nmaxthreads);
      /* Only master thread does this */
      if (tid == 0) 
        nthreads = omp_get_num_threads();
    	nproc =omp_get_num_procs();
        printf("Number of threads = %d\n", nthreads);
       printf("Number of processors = %d\n", nproc);
      }  /* All threads join master thread and disband */
    But it only prints once and says I have 1 thread. Running the function omp_get_max_threads() or omp_get_num_procs() says I have 4 though. Using omp_set_num_threads() doesn't change anything.

    Then I turned on OpenMP Support in Properties\C/C++\Language\OpenMP Support
    I also set the enviromental variable name: OMP_NUM_THREADS, value 4.

    The plugin is compiled as a Multi-threaded DLL (/MD).

    What's wrong in my settings ??? help please

  2. #2
    Registered User
    Join Date
    Jul 2011

    same problem!

    Could you find the cause of the problem.
    I have exactly the same problem and can't solve it
    Any help?


  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Same problem - people don't read the forum rules.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Terminating secondary thread from another thread
    By wssoh85 in forum C++ Programming
    Replies: 13
    Last Post: 12-19-2008, 05:14 AM
  2. printf+gets inside of code
    By tomas.ra in forum C Programming
    Replies: 7
    Last Post: 11-01-2005, 10:58 PM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Win32 Thread Object Model Revisted
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2004, 08:50 AM
  5. Lining up decimals & text - code included inside.
    By INFERNO2K in forum C Programming
    Replies: 7
    Last Post: 11-27-2004, 04:49 PM