<?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 Re:Simple example to Define function than call it from parallel_for kernal in Intel® oneAPI DPC++/C++ Compiler</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Simple-example-to-Define-function-than-call-it-from-parallel-for/m-p/1253957#M945</link>
    <description>&lt;P&gt;Hi Prilvesh Krishna,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the confirmation!&lt;/P&gt;&lt;P&gt;Glad to know that your issue is resolved.&lt;/P&gt;&lt;P&gt;As this issue has been resolved, we will no longer respond to this thread.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you require any additional assistance from Intel, please start a new thread.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any further interaction in this thread will be considered community only.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a Good day.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;I&gt;Thanks &amp;amp; Regards&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;I&gt;Goutham&lt;/I&gt;&lt;/P&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 08 Feb 2021 08:57:03 GMT</pubDate>
    <dc:creator>GouthamK_Intel</dc:creator>
    <dc:date>2021-02-08T08:57:03Z</dc:date>
    <item>
      <title>Simple example to Define function than call it from parallel_for kernal</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Simple-example-to-Define-function-than-call-it-from-parallel-for/m-p/1252733#M940</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;BR /&gt;Thanks for DPC++ It's great,&amp;nbsp; Is there&amp;nbsp; a simple example for&amp;nbsp; :&lt;BR /&gt;&lt;BR /&gt;Creating a simple&amp;nbsp; void function like&amp;nbsp; this and calling it from the&amp;nbsp; parallel_for kernal ?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#include &amp;lt;CL/sycl.hpp&amp;gt;&lt;BR /&gt;#include &amp;lt;iostream&amp;gt;&lt;/P&gt;
&lt;P&gt;using namespace sycl;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Void Mycustomfunction( int avariable ){&lt;/P&gt;
&lt;P&gt;&amp;nbsp; int myoutput=avariable+2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; return myoutput;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;int main(){&lt;/P&gt;
&lt;P&gt;int N =5;&lt;/P&gt;
&lt;P&gt;queue q ;&lt;/P&gt;
&lt;P&gt;int *data = malloc_shared&amp;lt;int&amp;gt;(N, q);&lt;/P&gt;
&lt;P&gt;for(int i = 0; N &amp;lt; 5; i++) {&lt;BR /&gt;data[i]=i;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;q.parallel_for(range&amp;lt;1&amp;gt;(N), [=] (id&amp;lt;1&amp;gt; i){&lt;BR /&gt;&lt;BR /&gt;data[i]=Mycustomfunction(i);&lt;BR /&gt;&lt;BR /&gt;}).wait();&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 10:57:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Simple-example-to-Define-function-than-call-it-from-parallel-for/m-p/1252733#M940</guid>
      <dc:creator>pril</dc:creator>
      <dc:date>2021-02-03T10:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Simple example to Define function than call it from parallel_for kernal</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Simple-example-to-Define-function-than-call-it-from-parallel-for/m-p/1253457#M942</link>
      <description>&lt;P&gt;Hi Prilvesh Krishna,&lt;/P&gt;
&lt;P&gt;&lt;I&gt;&amp;gt;&amp;gt;Thanks for DPC++ It's great,&amp;nbsp;&amp;nbsp;&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;Thank you for the kind feedback, we are glad to know that you liked DPC++.&lt;/P&gt;
&lt;P&gt;&lt;I&gt;&amp;gt;&amp;gt;Creating a simple&amp;nbsp;void function like&amp;nbsp;this and calling it from the&amp;nbsp;parallel_for kernal ?&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;You can achieve the above scenario in two ways.&lt;/P&gt;
&lt;P&gt;1) Use accessor datatype instead of int* variable inside the function definition /declaration.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;void Mycustomfunction(cl::sycl::accessor&amp;lt;int, 1, cl::sycl::access::mode::write&amp;gt; p, int x);&lt;/LI-CODE&gt;
&lt;P&gt;2) Typecast accessor address (aa) to (int *) inside the kernel and use int * in function definition/ declaration.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;void Mycustomfunction(int *p, int x);&lt;/LI-CODE&gt;
&lt;P&gt;Also, I'm attaching the complete working code sample(with both methods) below as per your requirement.&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;#include&amp;lt;iostream&amp;gt;
#include&amp;lt;CL/sycl.hpp&amp;gt;

using namespace std;
using namespace sycl;

//void Mycustomfunction(int *p, int x); For Method 2 uncomment this
void Mycustomfunction(cl::sycl::accessor&amp;lt;int, 1, cl::sycl::access::mode::write&amp;gt; p, int x);

int main()
{
   const int N=5;
    int a[N];
    for(int i=0;i&amp;lt;N;i++)
    {
        a[i]=i;
    }
    cpu_selector device_selector;
    queue q(device_selector);
    {
        buffer&amp;lt;int ,1&amp;gt; a_buff(a,range&amp;lt;1&amp;gt; (N));
        q.submit([&amp;amp;](handler &amp;amp;h)
        {
            auto aa=a_buff.get_access&amp;lt;access::mode::write&amp;gt;(h);
            h.parallel_for(range&amp;lt;1&amp;gt;{N},[=](id&amp;lt;1&amp;gt; item)
            {
                int index=item;
                Mycustomfunction(aa,index);
                 //Mycustomfunction((int *)&amp;amp;aa[0], index); For Method 2 uncomment this
            });
      });
    }
    for(int i=0;i&amp;lt;N;i++)
    {
        cout&amp;lt;&amp;lt;a[i]&amp;lt;&amp;lt;"\t";
    }
    cout&amp;lt;&amp;lt;"\n"&amp;lt;&amp;lt;std::endl;
}

void Mycustomfunction(cl::sycl::accessor&amp;lt;int, 1, cl::sycl::access::mode::write&amp;gt; p, int x){
        p[x]=x+2;
}

/* For Method 2 uncomment this
void Mycustomfunction(int *p,int x)
{
    p[x]=x+2;
}
*/
&lt;/LI-CODE&gt;
&lt;P&gt;Please feel free to reach out to us if you are facing any further issues in running this code.&lt;/P&gt;
&lt;P&gt;Have a Good day!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; Regards&lt;/P&gt;
&lt;P&gt;Goutham&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 11:56:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Simple-example-to-Define-function-than-call-it-from-parallel-for/m-p/1253457#M942</guid>
      <dc:creator>GouthamK_Intel</dc:creator>
      <dc:date>2021-02-05T11:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Simple example to Define function than call it from parallel_for kernal</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Simple-example-to-Define-function-than-call-it-from-parallel-for/m-p/1253518#M944</link>
      <description>&lt;P&gt;Thank you&amp;nbsp; &amp;nbsp;this example&amp;nbsp; works great .&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 15:03:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Simple-example-to-Define-function-than-call-it-from-parallel-for/m-p/1253518#M944</guid>
      <dc:creator>pril</dc:creator>
      <dc:date>2021-02-05T15:03:40Z</dc:date>
    </item>
    <item>
      <title>Re:Simple example to Define function than call it from parallel_for kernal</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Simple-example-to-Define-function-than-call-it-from-parallel-for/m-p/1253957#M945</link>
      <description>&lt;P&gt;Hi Prilvesh Krishna,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the confirmation!&lt;/P&gt;&lt;P&gt;Glad to know that your issue is resolved.&lt;/P&gt;&lt;P&gt;As this issue has been resolved, we will no longer respond to this thread.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you require any additional assistance from Intel, please start a new thread.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any further interaction in this thread will be considered community only.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a Good day.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;I&gt;Thanks &amp;amp; Regards&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;I&gt;Goutham&lt;/I&gt;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Feb 2021 08:57:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Simple-example-to-Define-function-than-call-it-from-parallel-for/m-p/1253957#M945</guid>
      <dc:creator>GouthamK_Intel</dc:creator>
      <dc:date>2021-02-08T08:57:03Z</dc:date>
    </item>
  </channel>
</rss>

