<?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 Hi, in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Using-Cilk-reducer-inside-Cilker-shared-function/m-p/1022607#M38883</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I don't know how your code uses the reducer object in the offloaded function, but there is a list of rules when using _Cilk_offload and _Cilk_shared as described in&amp;nbsp;https://software.intel.com/en-us/node/522499. Important rules for your code are:&lt;/P&gt;

&lt;UL id="GUID-FAC7D030-BF48-4021-B2BC-CE9CB14104B0" style="font-size: 13.0080003738403px; line-height: 19.5120010375977px;"&gt;
	&lt;LI id="LI_4FBE6E1687F8484B9AB0CCAF56AEFD8E"&gt;
		&lt;P style="margin-bottom: 0.5em;"&gt;When applied to a C++ class, all member functions are shared and all objects of that class type are shared.&lt;/P&gt;
	&lt;/LI&gt;
	&lt;LI id="LI_C4A1D653278C4A69A8B517BF12F3BE63"&gt;
		&lt;P style="margin-bottom: 0.5em;"&gt;Functions called from&amp;nbsp;&lt;SPAN class="keyword" style="font-family: 'Courier New', Courier, monospace;"&gt;_Cilk_offload _Cilk_for&lt;/SPAN&gt;&amp;nbsp;must be shared.&lt;/P&gt;
	&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;For this reason, your will have to declare all member functions as &lt;B&gt;"shared":&lt;/B&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#pragma offload_attribute(push, _Cilk_shared)
#include &amp;lt;list&amp;gt;
#include &amp;lt;cilk/reducer_list.h&amp;gt;
#pragma offload_attribute(pop)&lt;/PRE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;However, I don't think Cilk reducers are fully supported with _Cilk_shared keyword. I was not able to find a way to directly share a reduce_list object (e.g., by declaring it as a global _Cilk_shared variable), but the following one-directional use works fine:&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#define N 16
#pragma offload_attribute(push, _Cilk_shared)
#include &amp;lt;list&amp;gt;
#include &amp;lt;cilk/reducer_list.h&amp;gt;
int host_list&lt;N&gt;;
#pragma offload_attribute(pop)

#include &amp;lt;iostream&amp;gt;

_Cilk_shared
void dowork()
{
    cilk::reducer_list_append&amp;lt;int&amp;gt; list;
    _Cilk_for (int i = 0; i &amp;lt; N; ++i) {
        list-&amp;gt;push_back(i);
    }
    // copies target's reducer data to the shared plain container (host_list).
    std::list&amp;lt;int&amp;gt; &amp;amp;lout = list.get_reference();
    std::copy(lout.begin(), lout.end(), host_list);
}

int main()
{
    _Cilk_offload dowork();
    for (int i = 0; i &amp;lt; N; ++i) {
        std::cout &amp;lt;&amp;lt; host_list&lt;I&gt; &amp;lt;&amp;lt; std::endl;
    }
    return 0;
}&lt;/I&gt;&lt;/N&gt;&lt;/PRE&gt;

&lt;P&gt;This example may not be optimal in performance, but should give an answer how to collect the target's computation result at least.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Apr 2015 19:59:55 GMT</pubDate>
    <dc:creator>Hansang_B_Intel</dc:creator>
    <dc:date>2015-04-14T19:59:55Z</dc:date>
    <item>
      <title>Using Cilk reducer inside Cilker shared function</title>
      <link>https://community.intel.com/t5/Software-Archive/Using-Cilk-reducer-inside-Cilker-shared-function/m-p/1022606#M38882</link>
      <description>&lt;P&gt;Hi I am trying to offload some parallel work to MIC using _Cilk_Shared and _Cilk_offload.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;I declare a Cilk shared function:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;_Cilk_shared void somefun(int count)&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;In main I call this function using&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;_Cilk_offload somefun(12) ;&lt;/PRE&gt;

&lt;P&gt;inside this function everything is expected to be offloaded to MIC;&lt;/P&gt;

&lt;P&gt;I want to declare a Cilk reducer inside somefun, so I can then use cilk_for and append to a cilk reducer list,&amp;nbsp;&lt;/P&gt;

&lt;P&gt;but I get error:&lt;/P&gt;

&lt;PRE class="brush:;"&gt;error: illegal to declare an object of a class not marked _Cilk_shared, in a _Cilk_shared context
      cilk::reducer_list_append&amp;lt;int&amp;gt; rw;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;I know I can do this with offload pragma so I should be able to this with cilk shared as well right?&lt;/P&gt;

&lt;P&gt;I can't find concrete example of using _Cilk_shared and _Cilk_offload.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 13 Apr 2015 16:21:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Using-Cilk-reducer-inside-Cilker-shared-function/m-p/1022606#M38882</guid>
      <dc:creator>Jun</dc:creator>
      <dc:date>2015-04-13T16:21:48Z</dc:date>
    </item>
    <item>
      <title>Hi,</title>
      <link>https://community.intel.com/t5/Software-Archive/Using-Cilk-reducer-inside-Cilker-shared-function/m-p/1022607#M38883</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I don't know how your code uses the reducer object in the offloaded function, but there is a list of rules when using _Cilk_offload and _Cilk_shared as described in&amp;nbsp;https://software.intel.com/en-us/node/522499. Important rules for your code are:&lt;/P&gt;

&lt;UL id="GUID-FAC7D030-BF48-4021-B2BC-CE9CB14104B0" style="font-size: 13.0080003738403px; line-height: 19.5120010375977px;"&gt;
	&lt;LI id="LI_4FBE6E1687F8484B9AB0CCAF56AEFD8E"&gt;
		&lt;P style="margin-bottom: 0.5em;"&gt;When applied to a C++ class, all member functions are shared and all objects of that class type are shared.&lt;/P&gt;
	&lt;/LI&gt;
	&lt;LI id="LI_C4A1D653278C4A69A8B517BF12F3BE63"&gt;
		&lt;P style="margin-bottom: 0.5em;"&gt;Functions called from&amp;nbsp;&lt;SPAN class="keyword" style="font-family: 'Courier New', Courier, monospace;"&gt;_Cilk_offload _Cilk_for&lt;/SPAN&gt;&amp;nbsp;must be shared.&lt;/P&gt;
	&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;For this reason, your will have to declare all member functions as &lt;B&gt;"shared":&lt;/B&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#pragma offload_attribute(push, _Cilk_shared)
#include &amp;lt;list&amp;gt;
#include &amp;lt;cilk/reducer_list.h&amp;gt;
#pragma offload_attribute(pop)&lt;/PRE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;However, I don't think Cilk reducers are fully supported with _Cilk_shared keyword. I was not able to find a way to directly share a reduce_list object (e.g., by declaring it as a global _Cilk_shared variable), but the following one-directional use works fine:&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#define N 16
#pragma offload_attribute(push, _Cilk_shared)
#include &amp;lt;list&amp;gt;
#include &amp;lt;cilk/reducer_list.h&amp;gt;
int host_list&lt;N&gt;;
#pragma offload_attribute(pop)

#include &amp;lt;iostream&amp;gt;

_Cilk_shared
void dowork()
{
    cilk::reducer_list_append&amp;lt;int&amp;gt; list;
    _Cilk_for (int i = 0; i &amp;lt; N; ++i) {
        list-&amp;gt;push_back(i);
    }
    // copies target's reducer data to the shared plain container (host_list).
    std::list&amp;lt;int&amp;gt; &amp;amp;lout = list.get_reference();
    std::copy(lout.begin(), lout.end(), host_list);
}

int main()
{
    _Cilk_offload dowork();
    for (int i = 0; i &amp;lt; N; ++i) {
        std::cout &amp;lt;&amp;lt; host_list&lt;I&gt; &amp;lt;&amp;lt; std::endl;
    }
    return 0;
}&lt;/I&gt;&lt;/N&gt;&lt;/PRE&gt;

&lt;P&gt;This example may not be optimal in performance, but should give an answer how to collect the target's computation result at least.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2015 19:59:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Using-Cilk-reducer-inside-Cilker-shared-function/m-p/1022607#M38883</guid>
      <dc:creator>Hansang_B_Intel</dc:creator>
      <dc:date>2015-04-14T19:59:55Z</dc:date>
    </item>
    <item>
      <title>Thank you for you help!. I</title>
      <link>https://community.intel.com/t5/Software-Archive/Using-Cilk-reducer-inside-Cilker-shared-function/m-p/1022608#M38884</link>
      <description>&lt;P&gt;Thank you for you help!. I realized it yesterday that I need to push the library as _Cilk_shared.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Another question followed by this, I found that if I am using pragma offload_attributes with either _Cilk_shared or target(mic), &amp;nbsp;I should not define some librarys(cilk or iostream) outside of this pragma.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;I ran into this problem where If I define iostream outside the pragma I will get a run time error of can not load library blablabla&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;For example the simple code I attached , if I uncomment line 2(#define &amp;lt;iostream&amp;gt;) in RegionF.cxx, I will get a run time error can not load library&lt;/P&gt;

&lt;P&gt;compile: &amp;nbsp;icpc RegionF.cxx&lt;/P&gt;

&lt;P&gt;I am not sure this is intended or some bugs?&lt;/P&gt;

&lt;P&gt;I think I should open another threads in MIC topic.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2015 20:21:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Using-Cilk-reducer-inside-Cilker-shared-function/m-p/1022608#M38884</guid>
      <dc:creator>Jun</dc:creator>
      <dc:date>2015-04-14T20:21:38Z</dc:date>
    </item>
  </channel>
</rss>

