parallel two different thread

General OpenMP discussion

parallel two different thread

Postby lood339 » Tue Mar 27, 2012 7:50 pm

Hi, it's my first time to this forum. My problem is that.
I am an computer vision guy. I use an webcamera to capture image which is 30FPS. It means I will get an image every 30ms.
Now I have two things to do and they are seperately in two thread.
The first thread is find corner in each frame and record its reulst to .txt file. It will take about 20ms, that is less than 30ms.
The second thread starts when the first thread capture more than 200 frame. It read the result from the .txt file. And analysis the result. It costs longer time than 30ms, let us say it cost 1000ms.
I need to do these two things at the same time. How can I do?
Thanks very much.
lood339
 
Posts: 2
Joined: Tue Mar 27, 2012 7:41 pm

Re: parallel two different thread

Postby lood339 » Wed Mar 28, 2012 6:00 am

I found this example
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include <time.h>
#include <iostream>
using namespace std;

#define CHUNKSIZE 100
#define N 1000

int main()
{
   int i, chunk;
   float a[N], b[N], c[N], d[N];
   for (i = 0; i<N; ++i)
   {
      a[i] = i * 1.5;
      b[i] = i  + 22.35;
   }
   int id;
#pragma omp parallel shared(a, b, c, d) private(i, id)
   {
#pragma omp sections nowait
      {
#pragma omp section
         {
            id = omp_get_thread_num();
            printf("thread number = %d\n", id);            
            for (i = 0; i<N; ++i)
            {
               c[i] = a[i] + b[i];
            }
         }
#pragma  omp section
         {
            
            for (i =0; i<N; ++i)
            {
               d[i] = a[i] * b[i];
            }
         }
      }      
   }   
}

may useful. One section execuate one task, and each task doesn't need to wait others.
lood339
 
Posts: 2
Joined: Tue Mar 27, 2012 7:41 pm


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 6 guests