This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

openMP does not let debug breakpoint

Hi,
 I am  working with a TMDSEVM6678LE and I want to use
 a openMP example for adapt my code to use 8 cores. 

Now I am tryng openMp example using just 4 cores it prints
hello World form core 0,..,7 etc., until here everything is ok,
but when I add some code for sum values from two arrays and
store result in third one the breakpoints seems does not stop(does not appear
an arrow over blue circle instead a red dashed underlineunder blue circle) and values of variable are not available
in variables windows.

Here my code:

#include <ti/omp/omp.h>

#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <time.h>

#define NTHREADS  4

    int a[1000];
    int b[1000];
    int c[1000];
    int i;

void main()
{

int nthreads, tid,i,istart,iend;

nthreads = NTHREADS;
for(i=0;i<1000;i++)
{
    a[i]=i;
    b[i]=1;
}
omp_set_num_threads(NTHREADS);

/* Fork a team of threads giving them their own copies of variables */
#pragma omp parallel private(nthreads, tid,i, istart, iend)
  {

  /* Obtain thread number */
  tid = omp_get_thread_num();
  printf("Hello from core %d\n", tid);

  nthreads = omp_get_num_threads();
  printf("Core number is; %d\n", nthreads);

  istart = tid*1000/nthreads;
  iend = (tid+1)*1000/nthreads;
  for(i=istart;i<iend;i++)
  {
          c[i] = a[i] +b[i];

      printf("Thread[%d] sum [%d] is = %d\n",tid,i,c[i]);
  }
  a[1] = b[1];

  }  /* All threads join master thread and disband */

}



Any help will be appreciated.

Julian
  • Hi Julian

    I modified your code a bit to leverage the '#pragma omp for' directive instead. Please see the code below.

    #include <ti/omp/omp.h>

    #include <string.h>
    #include <assert.h>
    #include <stdio.h>
    #include <time.h>

    #define NTHREADS 4

    void main()
    {

    int nthreads, tid;
    int a[1000];
    int b[1000];
    int c[1000];
    int i;

    nthreads = NTHREADS;
    for(i=0;i<1000;i++)
    {
    a[i]=i;
    b[i]=1;
    }

    omp_set_num_threads(NTHREADS);

    /* Fork a team of threads giving them their own copies of variables */
    #pragma omp parallel private(nthreads, tid)
    {
    #pragma omp for
    for (i=0; i<NTHREADS; i++) {
    c[i] = a[i]+b[i];
    }

    /* Obtain thread number */
    tid = omp_get_thread_num();
    printf("Hello World from thread = %d\n", tid);

    /* Only master thread does this */
    if (tid == 0)
    {
    nthreads = omp_get_num_threads();
    printf("Number of threads = %d\n", nthreads);
    }

    } /* All threads join master thread and disband */

    }

    I then tried debugging this code on my setup here and was able to create and stop at breakpoints individually for each core.
    Try recreating the same breakpoint scenario on your setup. See the snapshot below. 

    You can see the variable window by going to 'View --> Variables' in your CCS Debug perspective, once you have halted at a breakpoint. I set all the other cores to break before the 'for' loop and let core C66x_1 proceed to the for loop. Then I open this 'Variables' window and can see the various variables including arrays a, b and c. Note that since the loop iteration is private to each core, OMP creates a 'temp_' variable to store the iteration count for private variables.

     

  • Uday,

    I tried the steps you suggested  and all work well.

    I tried with 8 cores and also work well.

    Now I am going to try my code in this example.

    Thanks, I appreciate your help.

    Julian