多线程两个功能使用openMP
multi threading two function using openMP
我在多线程和使用OpenMP方面绝对是新手。但我正在尝试开发一个具有两个功能的程序。
function1(){
get the data from the camera and save it into memory for 1000fps
}
functio2(){
display and refresh the screen each 100ms
}
我认为OpenMP应该是这样的
#pragma omp sections
{
{ function1(); }
#pragma omp section
{ function2(); }
}
,但我不知道我怎么能在代码中实际实现这一点(c++)?如果有人知道,请告诉我。我已经结束了下面的代码,但现在我想让第二部分睡眠每100ms,我怎么做呢?
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);
}
有多种方法可以做到这一点。如果您的编译器至少支持OpenMP 3.0,则可以使用task指令http://bisqwit.iki.fi/story/howto/openmp/TaskDirectiveOpenmp % 203% 200年只有
Visual Studio只有没有任务指令的OpenMP 2.0。我所做的是使用一个线程库。由于希望显示图像,因此可能需要考虑使用SDL。它具有与pthreads几乎相同的线程函数,并且使用简单(尽管不像OpenMP那么简单)。http://www.libsdl.org/intro.en/usingthreads.html
然后你有一个库可以显示你的图像,做线程,并且是跨平台的。
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 多态性和功能结合
- OpenMP阵列性能较差
- 带内存和隔离功能的SQLite
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- 类模板的成员功能的定义在单独的TU中完全专业化
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 如何在C++中获得"静态纯虚拟"功能?
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 两个文件使用彼此的功能-如何解决
- 我应该实现右值推送功能吗?我应该使用std::move吗
- QML按钮点击功能执行顺序
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 有没有可能有一个只有ADL才能找到的非好友功能
- 如何让线程继续并启动其他功能 - C++使用 OpenMP?
- OpenMP 慢速专用功能
- 如何在QThread中使用OpenMP功能强制使用多核
- 使用 OpenMP 并行化功能
- 多线程两个功能使用openMP