0
votes

I am absolutely newbie in multithreading and using OpenMP. but I am trying to develop a program with two function.

function1(){
get the data from the camera and save it into memory for 1000fps
}
functio2(){
display and refresh the screen each 100ms
}

I think the OpenMP should be something like this

#pragma omp sections
 {
   { function1(); }
   #pragma omp section
   { function2(); }
 }

but I am not sure how can I actually implement this in code (c++)? if somebody know can you please let me know. I have end up with the following code, but now I want to make the second section sleep every 100ms, how can I do it?

lastPicNr = 0;  
            if(Fg_AcquireEx(fg,nCamPort,GRAB_INFINITE,ACQ_STANDARD,_memoryAllc)<0){
                CExceptionHandler::GrabberErrorMessage(fg,"Can not start Acquiring images .");  
            }else{

                //Declaring a parallel region that will be broken down into disctinct parallel sections
                #pragma omp parallel sections
                {
                    #pragma omp section
                    {
                        while((lastPicNr = Fg_getLastPicNumberBlockingEx(fg,lastPicNr+1,nCamPort,10,_memoryAllc))<= MaxPics){   
                            iPtr=(unsigned char*)Fg_getImagePtrEx(fg,lastPicNr,0,_memoryAllc);      
                            _PointVector.push_back(iPtr);
                            _lastPicNumber.push_back(lastPicNr);                                
                        }
                    }

                    #pragma omp section
                    {
                        cv::Mat _matrixImage(cv::Size(w,h), CV_8UC1,iPtr , cv::Mat::AUTO_STEP);                                                                 
                        cv::imshow("test",_matrixImage);
                        cv::waitKey(10);

                    }
                }
                PauseClickMode(hDlg);
            }
1
Reading data is usually done via single thread, Implementing via parallel mode is not right. Also in order to refresh the image u may be using some kind of algorithm (e.g. smoothing function) over the image. You should parallelize that part. Calling functions in parallel will load each processor with the entire load of a image. Parallelising the "heart" of the code, you distribute this workload.DOOM

1 Answers

1
votes

There are various ways you can do this. If you have a compiler that supports at lest OpenMP 3.0 you can use the task directive http://bisqwit.iki.fi/story/howto/openmp/#TaskDirectiveOpenmp%203%200Only

Visual Studio only has OpenMP 2.0 which does not have the task directive. What I do is to use a threading library. Since you want to display an image you might want to consider SDL. It has threading functions which are almost identical to pthreads and is simple to use (though not as simple as OpenMP).
http://www.libsdl.org/intro.en/usingthreads.html

Then you have one library which can display your images, do threading, and is cross platform.