<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Second question: communication within threads in Intel® Moderncode for Parallel Architectures</title>
    <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Second-question-communication-within-threads/m-p/966498#M5426</link>
    <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;This is my second question. I am working on a computer vision project in which it is desirable using a two-thread parallel structure. The first thread grabs images from a camera continuously while the seond thread obtains information from the first thread. For example, we can grab images from the first thread and for each 10 frames, we display the last one from the second thread. Currently, I am using the opencv and openmp to do this work and the original program is attached here. However, it does not work properly and I am not sure what is the problem. As I am quite new to openmp, I'd like to see your suggestions regarding this issue. &lt;BR /&gt;&lt;BR /&gt;I am using a xeon 2cpu workstation with winxp system and intel c++ compiler 9.0. The opencv is with the version 4 beta. &lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;Jian</description>
    <pubDate>Thu, 27 Oct 2005 23:31:37 GMT</pubDate>
    <dc:creator>lijianemail</dc:creator>
    <dc:date>2005-10-27T23:31:37Z</dc:date>
    <item>
      <title>Second question: communication within threads</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Second-question-communication-within-threads/m-p/966498#M5426</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;This is my second question. I am working on a computer vision project in which it is desirable using a two-thread parallel structure. The first thread grabs images from a camera continuously while the seond thread obtains information from the first thread. For example, we can grab images from the first thread and for each 10 frames, we display the last one from the second thread. Currently, I am using the opencv and openmp to do this work and the original program is attached here. However, it does not work properly and I am not sure what is the problem. As I am quite new to openmp, I'd like to see your suggestions regarding this issue. &lt;BR /&gt;&lt;BR /&gt;I am using a xeon 2cpu workstation with winxp system and intel c++ compiler 9.0. The opencv is with the version 4 beta. &lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;Jian</description>
      <pubDate>Thu, 27 Oct 2005 23:31:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Second-question-communication-within-threads/m-p/966498#M5426</guid>
      <dc:creator>lijianemail</dc:creator>
      <dc:date>2005-10-27T23:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Second question: communication within threads</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Second-question-communication-within-threads/m-p/966499#M5427</link>
      <description>&lt;DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Hello again Jian,&lt;/P&gt;
&lt;P&gt;In OpenMP, threads communicate through shared variables. There is no event-based signaling mechanism. Communicating through shared variables requires synchronization. Your program has data races on at least two shared variables:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;A thread is reading &lt;FONT face="Courier New"&gt;nframe&lt;/FONT&gt; on lines 60 and 65 while another thread is writing &lt;FONT face="Courier New"&gt;nframe&lt;/FONT&gt; on line 51.&lt;/LI&gt;
&lt;LI&gt;The variable &lt;FONT face="Courier New"&gt;image&lt;/FONT&gt; is being written by one threadon line 45 while it is being read by the other thread on line 63.&lt;/LI&gt;&lt;/OL&gt;
&lt;DIV&gt;I just did a quick visual inspection of &lt;FONT face="Courier New"&gt;MT-SingleCam.c&lt;/FONT&gt; so there could be other errors that I missed. I encourage you to analyze your program with the &lt;A href="http://www.intel.com/cd/software/products/asmo-na/eng/219783.htm" target="_blank"&gt;Intel Threading Tools&lt;/A&gt;. Your program also relies on OpenCV being threadsafe. Does the OpenCV documentation comment on threadsafety?&lt;/DIV&gt;
&lt;DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;Best regards,&lt;/DIV&gt;
&lt;DIV&gt;Henry&lt;/DIV&gt;</description>
      <pubDate>Fri, 28 Oct 2005 03:13:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Second-question-communication-within-threads/m-p/966499#M5427</guid>
      <dc:creator>Henry_G_Intel</dc:creator>
      <dc:date>2005-10-28T03:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Second question: communication within threads</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Second-question-communication-within-threads/m-p/966500#M5428</link>
      <description>&lt;P&gt;In looking at your MT-SingleCam.c program I see some potential problem areas.&lt;/P&gt;
&lt;P&gt;1) int nframe, tid, nthreads;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;nframe shared between threads and it is not specified as being shared. That is one problem with nframe. The second problem is nframe should be specified as potentialy being modified ouside the current scope (or even inside scope via alternate thread. Try using&lt;/P&gt;
&lt;P&gt; volatile int nframe;&lt;/P&gt;
&lt;P&gt; int tid, nthreads;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;The second problem is the caputer bufferis (may be)in a state of flux while the second section is calling cvShowImage. e.g. on first pass nframe is 0 therefor nframe%10 is 0 and your code in the second sectionwill be calling cvShowImage for image 0 prior to or during the image capture of image 0. Consider changing the if statement to if((nframe-1)%10==0). This does not correct for the caputer buffer being overwritten during the display. (and remember to fix the printf to use nframe-1)&lt;/P&gt;
&lt;P&gt;I would suggest you experiment with the code and use two capture buffers. Double buffering technique. Or two buffers - mostly single buffered with second buffer flag protected and used for the intermittant update.&lt;/P&gt;
&lt;P&gt; if(SecondBufferReady)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;image=cvQueryFrame(SecondCapture);&lt;/P&gt;
&lt;P&gt;SecondBufferReady = 0;&lt;/P&gt;
&lt;P&gt; } else {&lt;/P&gt;
&lt;P&gt;image=cvQueryFrame(FirstCapture);&lt;/P&gt;
&lt;P&gt; }&lt;/P&gt;
&lt;P&gt;Decorate the code with the nframe%DisplayRefreshFrequency&lt;/P&gt;
&lt;P&gt;If two capture buffers don't fit in with your design interests then consider moving the nframe++; statement to the line following image=cvQueryFrame. That way the two paints can happen somewhat in parallel. Still not error free but will exhibit a lower probability for problems.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 28 Oct 2005 05:49:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Second-question-communication-within-threads/m-p/966500#M5428</guid>
      <dc:creator>jim_dempsey</dc:creator>
      <dc:date>2005-10-28T05:49:39Z</dc:date>
    </item>
  </channel>
</rss>

