<?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 It would be very kind of you  in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Regarding-intel-MIC-offload-error-buffer-write-failed/m-p/1000625#M30007</link>
    <description>&lt;P&gt;Thankyou very much Sunny, Your previous reply resolved my issue.&amp;nbsp; It would be very kind of you&amp;nbsp; if you can explain the reason that why&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;fp = (FILE *)malloc(sizeof(FILE *));&lt;/PRE&gt;

&lt;P&gt;makes my program work correctly ?&lt;/P&gt;

&lt;UL&gt;
	&lt;LI&gt;&lt;STRONG&gt;Follow up question:&lt;/STRONG&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;AFAIK the&lt;EM&gt; best way of getting private pointer&lt;/EM&gt; in omp is to get dynamic memory within parallel region!!&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#pragma omp parallel
{
    fp=malloc(sizeof(FILE*));
}&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Approach 1:&lt;/STRONG&gt;&lt;BR /&gt;
	Sharing a pointer seems no use here !!&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;omp.h&amp;gt;
void main()
{
char *p;
p=(char*)malloc(sizeof(char)*1);
#pragma omp parallel private(p)
{
  printf("%p\n",p);
}
}&lt;/PRE&gt;

&lt;P&gt;Output: (nil)&lt;BR /&gt;
	(nil)&lt;BR /&gt;
	(nil)&lt;BR /&gt;
	(nil)&lt;BR /&gt;
	(nil)&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Approach 2:&lt;/STRONG&gt;&lt;BR /&gt;
	and here clearly, i am getting private pointers, but this approach makes my offload program wait!!!&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;omp.h&amp;gt;

void main()
{
 char *p;
#pragma omp parallel private(p)
{
p=(char*)malloc(sizeof(char)*1);
  printf("%p\n",p);
}
}&lt;/PRE&gt;

&lt;P&gt;Output:0xae49b0&lt;BR /&gt;
	0x2b787c000950&lt;BR /&gt;
	0x2b7880000950&lt;BR /&gt;
	0x2b7874000950&lt;BR /&gt;
	0x2b7870000950&lt;/P&gt;

&lt;P&gt;So&lt;STRONG&gt; as per approach 2 ,I modified my offload code &lt;/STRONG&gt;slightly for getting more threads(initializing fp within parallel region).This code simply hangs up (seems like it waits for something!!) and does not produce any error:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;FILE *fp;
char data[100];
#pragma omp parallel default(none)  private(fp,data)
#pragma offload target(mic:0) inout(fp,data)
{
    fp = (FILE *)malloc(sizeof(FILE *));
    fp=popen("uname -p","r");
    fread(data,sizeof(char),100,fp);
    pclose(fp);
    puts(data);
}
    if(fp!=NULL)
        free(fp);
return 0;
&lt;/PRE&gt;

&lt;P&gt;Though ,the following is not the best way of getting private pointer ; approach 1 sets my program work fine(with the fp initiallized before omp parallel region)&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;FILE *fp;
char data[100];
        fp = (FILE *)malloc(sizeof(FILE *));
#pragma omp parallel default(none)  private(fp,data)
#pragma offload target(mic:0) inout(fp,data)
{
        fp=popen("uname -p","r");
        fread(data,sizeof(char),100,fp);
        pclose(fp);
        puts(data);
}
        if(fp!=NULL)
                free(fp);
return 0;
&lt;/PRE&gt;

&lt;P&gt;What might be the reason behind this behaviour ?any hints/suggestions will be very useful !&lt;/P&gt;</description>
    <pubDate>Mon, 06 Apr 2015 06:30:00 GMT</pubDate>
    <dc:creator>psing51</dc:creator>
    <dc:date>2015-04-06T06:30:00Z</dc:date>
    <item>
      <title>Regarding intel MIC offload error: buffer write failed</title>
      <link>https://community.intel.com/t5/Software-Archive/Regarding-intel-MIC-offload-error-buffer-write-failed/m-p/1000622#M30004</link>
      <description>&lt;PRE&gt;I am trying to explore the code offloading construct .In the following program
 the offloaded region fetches the architecture of MIC card.&lt;/PRE&gt;

&lt;PRE class="brush:bash;"&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;omp.h&amp;gt;
void main()
{
  FILE *fp,*fp1;
 char data[100],data1[100],final[100];
#pragma offload target(mic: 0) inout(data , fp)
{
	fp=popen("uname -m","r");
	fread(data, sizeof(char),100 , fp);
	fclose(fp);
}
	puts(data);
}
&lt;/PRE&gt;

&lt;PRE&gt;Here are three sample runs of this program:&lt;/PRE&gt;

&lt;UL&gt;
	&lt;LI&gt;The first run succeeds ,&lt;/LI&gt;
	&lt;LI&gt;Second run hangs(manually killing program using &lt;STRONG&gt;^C&lt;/STRONG&gt; )&lt;/LI&gt;
	&lt;LI&gt;Third run gives&lt;STRONG&gt; buffer write fail &lt;/STRONG&gt;error&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;&lt;BR /&gt;
	&lt;STRONG&gt;[puneet@paramshavak NWCHEM_INTEL_MICOFFLOAD]$ ./a.out&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;[Offload] [MIC 0] [File]                    omp.c
[Offload] [MIC 0] [Line]                    8
[Offload] [MIC 0] [Tag]                     Tag 0
HOST:  Offload function __offload_entry_omp_c_8mainicc161915962IRh4TM, is_empty=0, #varDescs=4, #waits=0, signal=none
HOST:  Total pointer data sent to target: [316] bytes
HOST:  Total copyin data sent to target: [16] bytes
HOST:  Total pointer data received from target: [316] bytes
MIC0:  Calling COIBufferAddRef 0x7f4cbd802000
MIC0:      AddRef count = 1
MIC0:  Calling COIBufferAddRef 0x7f4cbd7ff000
MIC0:      AddRef count = 1
MIC0:  Total copyin data received from host: [16] bytes
MIC0:  Total copyout data sent to host: [0] bytes
HOST:  Total copyout data received from target: [0] bytes
[Offload] [HOST]  [Tag 0] [CPU Time]        0.265805(seconds)
[Offload] [MIC 0] [Tag 0] [MIC Time]        0.036923(seconds)

k1om

**************************************************************
                             timer data       (sec)
**************************************************************&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;[puneet@paramshavak NWCHEM_INTEL_MICOFFLOAD]$ ./a.out&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;[Offload] [MIC 0] [File]                    omp.c
[Offload] [MIC 0] [Line]                    8
[Offload] [MIC 0] [Tag]                     Tag 0
HOST:  Offload function __offload_entry_omp_c_8mainicc161915962IRh4TM, is_empty=0, #varDescs=4, #waits=0, signal=none
HOST:  Total pointer data sent to target: [316] bytes
HOST:  Total copyin data sent to target: [16] bytes
HOST:  Total pointer data received from target: [316] bytes
MIC0:  Calling COIBufferAddRef 0x7f8eeedd3000
MIC0:      AddRef count = 1
MIC0:  Calling COIBufferAddRef 0x7f8eeedd1000
MIC0:      AddRef count = 1
MIC0:  Total copyin data received from host: [16] bytes
MIC0:  Total copyout data sent to host: [0] bytes
HOST:  Total copyout data received from target: [0] bytes

^C&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;[puneet@paramshavak NWCHEM_INTEL_MICOFFLOAD]$ ./a.out&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;[Offload] [MIC 0] [File]                    omp.c
[Offload] [MIC 0] [Line]                    8
[Offload] [MIC 0] [Tag]                     Tag 0
HOST:  Offload function __offload_entry_omp_c_8mainicc161915962IRh4TM, is_empty=0, #varDescs=4, #waits=0, signal=none
offload error: buffer write failed (error code 6)


**************************************************************
                             timer data       (sec)
**************************************************************
      Offload from file omp.cLine 8
          host: total offload time                   0.00000
            host: initialize target                  0.20055
            host: acquire target                     0.00014
            host: wait dependencies                  0.00000
            host: setup buffers                      0.00383
              host: allocate buffers                 0.00159
            host: setup misc_data                    0.00000
              host: allocate buffer                  0.00000
            host: send pointers                      0.00000
            host: gather inputs                      0.00000
              host: map IN data buffer               0.00000
              host: unmap IN data buffer             0.00000
            host: initiate compute                   0.00000
            host: wait compute                       0.00000
            host: initiate pointer reads             0.00000
            host: scatter outputs                    0.00000
              host: map OUT data buffer              0.00000
              host: unmap OUT data buffer            0.00000
            host: wait pointer reads                 0.00000
            host: destroy buffers                    0.00000
          target: total time                         0.00000javascript:void(0)
            target: setup offload descriptor         0.00000
            target: entry lookup                     0.00000
            target: entry time                       0.00000
              target: scatter inputs                 0.00000
                target: add buffer reference         0.00000
              target: compute                        0.00000
              target: gather outputs                 0.00000
                target: remove buffer reference      0.00000

&lt;/PRE&gt;

&lt;P&gt;Am i missing out on some essentials here ?(buffer cleanup etc.) .Some insight into the reason &amp;amp; solution will be very useful.&lt;BR /&gt;
	Eagerly Awaiting your replies,&lt;BR /&gt;
	Regards,&lt;BR /&gt;
	Puneet Singh&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2015 11:04:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Regarding-intel-MIC-offload-error-buffer-write-failed/m-p/1000622#M30004</guid>
      <dc:creator>psing51</dc:creator>
      <dc:date>2015-03-30T11:04:47Z</dc:date>
    </item>
    <item>
      <title>Puneet,</title>
      <link>https://community.intel.com/t5/Software-Archive/Regarding-intel-MIC-offload-error-buffer-write-failed/m-p/1000623#M30005</link>
      <description>&lt;P&gt;Puneet,&lt;/P&gt;

&lt;P&gt;What version of the Intel compiler are you using? You should have received a warning about fp being a pointer with no data associated with it.&lt;/P&gt;

&lt;P&gt;Why are you passing the pointer fp to the offload section?&lt;/P&gt;

&lt;P&gt;Regards&lt;BR /&gt;
	--&lt;BR /&gt;
	Taylor&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Apr 2015 22:40:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Regarding-intel-MIC-offload-error-buffer-write-failed/m-p/1000623#M30005</guid>
      <dc:creator>TaylorIoTKidd</dc:creator>
      <dc:date>2015-04-01T22:40:36Z</dc:date>
    </item>
    <item>
      <title>Hello Puneet,</title>
      <link>https://community.intel.com/t5/Software-Archive/Regarding-intel-MIC-offload-error-buffer-write-failed/m-p/1000624#M30006</link>
      <description>&lt;P&gt;Hello Puneet,&lt;/P&gt;

&lt;P&gt;Can you please verify if you get the expected results with the following update to your code:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;omp.h&amp;gt;
void main()
{
  FILE *fp,*fp1;
  //dummy initialization of fp
  //otherwise you pass null pointer     
  fp = (FILE *)malloc(sizeof(FILE *));
 char data[100],data1[100],final[100];
#pragma offload target(mic: 0) inout(data, fp)
{
        fp=popen("uname -m","r");
        if(NULL != fp){
                fread(data, sizeof(char),100 , fp);
                pclose(fp);
        puts(data);
        }
}
 
        if(NULL != fp)
                free(fp);
}
&lt;/PRE&gt;

&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Sat, 04 Apr 2015 00:20:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Regarding-intel-MIC-offload-error-buffer-write-failed/m-p/1000624#M30006</guid>
      <dc:creator>Sunny_G_Intel</dc:creator>
      <dc:date>2015-04-04T00:20:00Z</dc:date>
    </item>
    <item>
      <title>It would be very kind of you </title>
      <link>https://community.intel.com/t5/Software-Archive/Regarding-intel-MIC-offload-error-buffer-write-failed/m-p/1000625#M30007</link>
      <description>&lt;P&gt;Thankyou very much Sunny, Your previous reply resolved my issue.&amp;nbsp; It would be very kind of you&amp;nbsp; if you can explain the reason that why&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;fp = (FILE *)malloc(sizeof(FILE *));&lt;/PRE&gt;

&lt;P&gt;makes my program work correctly ?&lt;/P&gt;

&lt;UL&gt;
	&lt;LI&gt;&lt;STRONG&gt;Follow up question:&lt;/STRONG&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;AFAIK the&lt;EM&gt; best way of getting private pointer&lt;/EM&gt; in omp is to get dynamic memory within parallel region!!&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#pragma omp parallel
{
    fp=malloc(sizeof(FILE*));
}&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Approach 1:&lt;/STRONG&gt;&lt;BR /&gt;
	Sharing a pointer seems no use here !!&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;omp.h&amp;gt;
void main()
{
char *p;
p=(char*)malloc(sizeof(char)*1);
#pragma omp parallel private(p)
{
  printf("%p\n",p);
}
}&lt;/PRE&gt;

&lt;P&gt;Output: (nil)&lt;BR /&gt;
	(nil)&lt;BR /&gt;
	(nil)&lt;BR /&gt;
	(nil)&lt;BR /&gt;
	(nil)&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Approach 2:&lt;/STRONG&gt;&lt;BR /&gt;
	and here clearly, i am getting private pointers, but this approach makes my offload program wait!!!&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;omp.h&amp;gt;

void main()
{
 char *p;
#pragma omp parallel private(p)
{
p=(char*)malloc(sizeof(char)*1);
  printf("%p\n",p);
}
}&lt;/PRE&gt;

&lt;P&gt;Output:0xae49b0&lt;BR /&gt;
	0x2b787c000950&lt;BR /&gt;
	0x2b7880000950&lt;BR /&gt;
	0x2b7874000950&lt;BR /&gt;
	0x2b7870000950&lt;/P&gt;

&lt;P&gt;So&lt;STRONG&gt; as per approach 2 ,I modified my offload code &lt;/STRONG&gt;slightly for getting more threads(initializing fp within parallel region).This code simply hangs up (seems like it waits for something!!) and does not produce any error:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;FILE *fp;
char data[100];
#pragma omp parallel default(none)  private(fp,data)
#pragma offload target(mic:0) inout(fp,data)
{
    fp = (FILE *)malloc(sizeof(FILE *));
    fp=popen("uname -p","r");
    fread(data,sizeof(char),100,fp);
    pclose(fp);
    puts(data);
}
    if(fp!=NULL)
        free(fp);
return 0;
&lt;/PRE&gt;

&lt;P&gt;Though ,the following is not the best way of getting private pointer ; approach 1 sets my program work fine(with the fp initiallized before omp parallel region)&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;FILE *fp;
char data[100];
        fp = (FILE *)malloc(sizeof(FILE *));
#pragma omp parallel default(none)  private(fp,data)
#pragma offload target(mic:0) inout(fp,data)
{
        fp=popen("uname -p","r");
        fread(data,sizeof(char),100,fp);
        pclose(fp);
        puts(data);
}
        if(fp!=NULL)
                free(fp);
return 0;
&lt;/PRE&gt;

&lt;P&gt;What might be the reason behind this behaviour ?any hints/suggestions will be very useful !&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2015 06:30:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Regarding-intel-MIC-offload-error-buffer-write-failed/m-p/1000625#M30007</guid>
      <dc:creator>psing51</dc:creator>
      <dc:date>2015-04-06T06:30:00Z</dc:date>
    </item>
    <item>
      <title>Hello Puneet,</title>
      <link>https://community.intel.com/t5/Software-Archive/Regarding-intel-MIC-offload-error-buffer-write-failed/m-p/1000626#M30008</link>
      <description>&lt;P&gt;Hello Puneet,&lt;/P&gt;

&lt;P&gt;Please find some of the possible reasons you are seeing the above behavior.&lt;/P&gt;

&lt;P&gt;1. Why allocating fp works?&lt;/P&gt;

&lt;P&gt;This is because when a program runs in a heterogeneous environment (with host and coprocessors), program variables are copied back and forth between CPU and the target. So if you don't initialize fp and try to offload, you basically sign up for copy from a uninitialized variable (null pointer - in our case).&lt;/P&gt;

&lt;P&gt;2. Also as per my knowledge when you use openMP parallel with private clause: &amp;nbsp;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;A new variable of the same type is declared once for each thread and that variable should be assumed to be uninitialized. You will still be able to use same variable name, however all your references will be replaced by new per thread variables.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Considering the above 2 conditions, you might have to do both to get expected result: Initialize &lt;STRONG&gt;fp&lt;/STRONG&gt; outside and then initialized per thread &lt;STRONG&gt;fp&amp;nbsp;&lt;/STRONG&gt;inside openMP &amp;nbsp;region as follows:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;omp.h&amp;gt;
 
int main(){
        FILE *fp;
        fp = (FILE *)malloc(sizeof(FILE *));
        char data[100];
#pragma omp parallel default(none)  private(fp,data)
#pragma offload target(mic:0) inout(fp,data)
{
        fp = (FILE *)malloc(sizeof(FILE *));
        fp=popen("uname -m","r");
        fread(data,sizeof(char),100,fp);
        pclose(fp);
        puts(data);
}
        if(fp!=NULL)
        free(fp);
        return 0;
}&lt;/PRE&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.0080003738403px; line-height: 19.5120010375977px;"&gt;Also if you don't mind, can you please explain me what are you trying to achieve here?&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 13.0080003738403px; line-height: 19.5120010375977px;"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2015 17:59:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Regarding-intel-MIC-offload-error-buffer-write-failed/m-p/1000626#M30008</guid>
      <dc:creator>Sunny_G_Intel</dc:creator>
      <dc:date>2015-04-06T17:59:51Z</dc:date>
    </item>
  </channel>
</rss>

