Hello all,

I am trying to implement some code in OpenMP under Octave, but I have 
some problems.

#include <omp.h>
#include <octave/oct.h>
    
     DEFUN_DLD (pmean, args, , "Calculates then mean in parallel")
     {
       int nargin = args.length ();
      
       Matrix m (1,1);


       int tid,nthreads;
       omp_set_num_threads(2);
       #pragma omp parallel private( nthreads, tid)
       tid = omp_get_thread_num();
       nthreads = omp_get_num_threads();
       octave_stdout << "Thread "<< tid << " of " << nthreads << " 
threads \n.";
       if (nargin != 1)
         print_usage ();
       else
         {
           NDArray A = args(0).array_value ();
      
      
       
        #pragma omp parallel for reduction(+:m)
        for (octave_idx_type i = 0; i < A.nelem (); i++){
                       m = m + A.elem (i)/A.nelem ();
        }

                 return octave_value (m);

         }

     }

This code is supposed to calculate a mean of an Octave matrix in 
parallel: some iterations of the for will be done by different threads.

I set the number of threads to 2 (omp_set_num_threads(2)). I compiled 
and linked it nicely but, unfortunatelly, when I executed it:

octave:1> pmean([10 0 5])
Thread 0 of 1 threads
.ans =  5

One thread is executed instead. I don't really know how to solve this 
problem, even don't know where I have to look for. Does anyone of you 
have treated this problem before?

Thank you in advance,

Miguel

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to