title: Reading files to shared memory
body: <p>I am reading a binary file that I want to offload directly to the Xeon Phi through Cilk and shared memory.</p>
  
  <p>As we are reading fairly much data at once each time and binary data the preferred option is to use fread. </p>
  
  <p>So if I make a very simple example it would go like this</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdint.h&gt;
  
  _Cilk_shared uint8_t* _Cilk_shared buf;
  
  int main(int argc, char **argv) {
    printf("Argv is %s\n", argv[1]);
    FILE* infile = fopen(argv[1], "rb");
    buf = (_Cilk_shared uint8_t*) _Offload_shared_malloc(2073600);
    int len = fread(buf, 1, 2073600, infile);
    if(ferror(infile)) {
      perror("ferror");
    }
    printf("Len is %d and first value of buf is %d\n", len, *buf);
    return 0;
  }
  </code></pre>
  
  <p>The example is very simplified from the real code but enough to examplify the behavior.</p>
  
  <p>This code would then return </p>
  
  <pre><code>ferror: Bad address
  Len is 0 and first value of buf is 0
  </code></pre>
  
  <p>However if we switch out the fread for a fgets (not very suitable for reading binary data, specially with the return value) things work great. </p>
  
  <p>That is we switch <code>fgets((char *) buf, 2073600, infile);</code> and then drop the len from the print out we get </p>
  
  <p><code>first value of buf is 46</code></p>
  
  <p>Which fits with what we need and I can run <code>_Offload_cilk</code> on a function with buf as an argument and do work on it.</p>
  
  <p>Is there something I am missing or is fread just not supported? I've tried to find as much info on this from both intel and other sites on the internet but I have sadly been unable to.</p>
  
  <p>----EDIT----</p>
  
  <p>After more research into this it seems that running fread on the shared memory with a value higher than 524287 (524287 is 19 bits exactly) fread gets the error from above. At 524287 or lower things work, and you can run as many fread as you want and read all the data.</p>
  
  <p>I am utterly unable to find any reason written anywhere for this.</p>