Like Tree1Likes
  • 1 Post By Salem

only one thread shows on openMP code inside

This is a discussion on only one thread shows on openMP code inside within the C++ Programming forums, part of the General Programming Boards category; seems I am able to access all the OpenMP functions by just including omp.h. Tried running the example: Code: #include ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    1

    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:

    Code:
    #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);
      nmaxthreads=omp_get_max_threads(); 
      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
    Posts
    1

    same problem!

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

    Thanks,

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Same problem - people don't read the forum rules.
    AndrewHunter likes this.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 04:14 AM
  2. printf+gets inside of code
    By tomas.ra in forum C Programming
    Replies: 7
    Last Post: 11-01-2005, 09:58 PM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Win32 Thread Object Model Revisted
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2004, 07:50 AM
  5. Lining up decimals & text - code included inside.
    By INFERNO2K in forum C Programming
    Replies: 7
    Last Post: 11-27-2004, 03:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21