<?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 How can I use parallel_for to pass two dimensional arrays? in Intel® Moderncode for Parallel Architectures</title>
    <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/How-can-I-use-parallel-for-to-pass-two-dimensional-arrays/m-p/803055#M688</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I found a way to get around the problem. Just pass one dimensional arrays and convert them to two dimensional arrays later. &lt;BR /&gt;&lt;BR /&gt;Ying</description>
    <pubDate>Wed, 09 Jun 2010 22:04:32 GMT</pubDate>
    <dc:creator>yingemmachen</dc:creator>
    <dc:date>2010-06-09T22:04:32Z</dc:date>
    <item>
      <title>How can I use parallel_for to pass two dimensional arrays?</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/How-can-I-use-parallel-for-to-pass-two-dimensional-arrays/m-p/803054#M687</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I tried to use parallel_for to speed up our c++ program. It seems very easy to use. However, in the function which is to be parallelized, a few 2D arrays calculated in the function need be passed to the main funciton. In the example (sub_string_finder.cpp), one dimensional arrays are modified in the SubStringFinder by using the addresses of these arrays. Please see the code below. I am wondering if I can use similar trick, but not sure how to use it on 2D arrays.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Ying&lt;BR /&gt;&lt;BR /&gt;--------------------------------------------------------------------------------------------------------------&lt;BR /&gt;&lt;BR /&gt;#include &lt;IOSTREAM&gt;&lt;BR /&gt;#include &lt;STRING&gt;&lt;BR /&gt;#include &lt;ALGORITHM&gt;&lt;BR /&gt;&lt;BR /&gt;#include "tbb/parallel_for.h"&lt;BR /&gt;#include "tbb/blocked_range.h"&lt;BR /&gt;&lt;BR /&gt;using namespace tbb;&lt;BR /&gt;using namespace std;&lt;BR /&gt;&lt;BR /&gt;static const size_t N = 23;&lt;BR /&gt;&lt;BR /&gt;class SubStringFinder {&lt;BR /&gt;const string str;&lt;BR /&gt;size_t *max_array;&lt;BR /&gt;size_t *pos_array;&lt;BR /&gt;public:&lt;BR /&gt;void operator() ( const blocked_range&lt;SIZE_T&gt;&amp;amp; r ) const {&lt;BR /&gt; for ( size_t i = r.begin(); i != r.end(); ++i ) {&lt;BR /&gt; size_t max_size = 0, max_pos = 0;&lt;BR /&gt; for (size_t j = 0; j &amp;lt; str.size(); ++j) &lt;BR /&gt; if (j != i) {&lt;BR /&gt; size_t limit = str.size()-( i &amp;gt; j ? i : j );&lt;BR /&gt; for (size_t k = 0; k &amp;lt; limit; ++k) {&lt;BR /&gt; if (str[i + k] != str[j + k]) break;&lt;BR /&gt; if (k &amp;gt; max_size) {&lt;BR /&gt; max_size = k;&lt;BR /&gt; max_pos = j;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; max_array&lt;I&gt; = max_size;&lt;BR /&gt; pos_array&lt;I&gt; = max_pos;&lt;BR /&gt; }&lt;BR /&gt;}&lt;BR /&gt;SubStringFinder(string &amp;amp;s, size_t *m, size_t *p) : &lt;BR /&gt; str(s), max_array(m), pos_array(p) { }&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char *argv[]) {&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;string str&lt;N&gt; = { string("a"), string("b") };&lt;BR /&gt;for (size_t i = 2; i &amp;lt; N; ++i) str&lt;I&gt; = str[i-1]+str[i-2];&lt;BR /&gt;string &amp;amp;to_scan = str[N-1]; &lt;BR /&gt;&lt;BR /&gt;size_t *max = new size_t[to_scan.size()];&lt;BR /&gt;size_t *pos = new size_t[to_scan.size()];&lt;BR /&gt;&lt;BR /&gt;parallel_for(blocked_range&lt;SIZE_T&gt;(0, to_scan.size(), 100),&lt;BR /&gt; SubStringFinder( to_scan, max, pos ) );&lt;BR /&gt;&lt;BR /&gt;for (size_t i = 0; i &amp;lt; to_scan.size(); ++i)&lt;BR /&gt; cout &amp;lt;&amp;lt; " " &amp;lt;&amp;lt; (int)max&lt;I&gt; &amp;lt;&amp;lt; "(" &amp;lt;&amp;lt; (int)pos&lt;I&gt; &amp;lt;&amp;lt; ")" &amp;lt;&amp;lt; endl;&lt;BR /&gt;delete[] max;&lt;BR /&gt;delete[] pos;&lt;BR /&gt;return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;/I&gt;&lt;/I&gt;&lt;/SIZE_T&gt;&lt;/I&gt;&lt;/N&gt;&lt;/I&gt;&lt;/I&gt;&lt;/SIZE_T&gt;&lt;/ALGORITHM&gt;&lt;/STRING&gt;&lt;/IOSTREAM&gt;</description>
      <pubDate>Tue, 08 Jun 2010 15:42:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/How-can-I-use-parallel-for-to-pass-two-dimensional-arrays/m-p/803054#M687</guid>
      <dc:creator>yingemmachen</dc:creator>
      <dc:date>2010-06-08T15:42:19Z</dc:date>
    </item>
    <item>
      <title>How can I use parallel_for to pass two dimensional arrays?</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/How-can-I-use-parallel-for-to-pass-two-dimensional-arrays/m-p/803055#M688</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I found a way to get around the problem. Just pass one dimensional arrays and convert them to two dimensional arrays later. &lt;BR /&gt;&lt;BR /&gt;Ying</description>
      <pubDate>Wed, 09 Jun 2010 22:04:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/How-can-I-use-parallel-for-to-pass-two-dimensional-arrays/m-p/803055#M688</guid>
      <dc:creator>yingemmachen</dc:creator>
      <dc:date>2010-06-09T22:04:32Z</dc:date>
    </item>
    <item>
      <title>How can I use parallel_for to pass two dimensional arrays?</title>
      <link>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/How-can-I-use-parallel-for-to-pass-two-dimensional-arrays/m-p/803056#M689</link>
      <description>Usualy you iterate on the row index.</description>
      <pubDate>Wed, 09 Jun 2010 23:45:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Moderncode-for-Parallel/How-can-I-use-parallel-for-to-pass-two-dimensional-arrays/m-p/803056#M689</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2010-06-09T23:45:56Z</dc:date>
    </item>
  </channel>
</rss>

