Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

Second question: communication within threads

lijianemail
Beginner
251 Views
Hi all, This is the second question. What I want to do is starting two threads using openmp. The first thread grabs image from a camera and the second thread obtains information (images) from the first thread with a constant temporal interval. For example, thread 1 grabs images continuously and thread 2 displays a frame of image in the first thread every 10 frames. For this task, it seems there should be some parameters which can be shared within threads. Currently, I am using a omp section directive, in which the image is shared between two threads. However, my program does not work properly. Could please offer me some suggestion regarding this issue. Thanks a lot. The original program is shown as below: #include "cv.h" #include "highgui.h" #include #include void main() { IplImage *image; CvCapture *capture; int nframe, tid, nthreads; capture=cvCaptureFromCAM(-1); cvNamedWindow("show1", 0); cvNamedWindow("show2", 0); omp_set_num_threads(2); nframe=0; for (;;) { #pragma omp parallel shared(image) private(tid) { tid=omp_get_thread_num(); if (tid==0) { nthreads=omp_get_num_threads(); printf("Number of threads = %d ", nthreads); } printf("Thread %d starting.... ", tid); #pragma omp sections nowait { #pragma omp section { printf("Thread %d grabbing from the camera ", tid); image=cvQueryFrame(capture); cvShowImage("show1", image); printf("This is the No %d frame from the camera ", nframe); nframe++; } #pragma omp section { printf("Thread %d obtains frames from camera ", tid); if (nframe%10==0) { cvShowImage("show2", image); printf("This is the copy of No %d frame from camera ", nframe); } } } } if (cvWaitKey(10)>=0) break; } cvReleaseCapture(&capture); cvDestroyAllWindows(); }
0 Kudos
0 Replies
Reply