title: Shared memory in parallel foreach in R
body: <p>Problem Description:</p>
  
  <p>I have a big matrix <code>c</code>, loaded in RAM memory. My goal is through parallel processing to have read only access to it. However when I create the connections either I use <code>doSNOW</code>, <code>doMPI</code>, <code>big.matrix</code>, etc the amount to ram used increases dramatically.</p>
  
  <p><strong>Is there a way to properly create a shared memory, where all the processes may read from, without creating a local copy of all the data?</strong></p>
  
  <p>Example:</p>
  
  <pre><code>libs&lt;-function(libraries){# Installs missing libraries and then load them
    for (lib in libraries){
      if( !is.element(lib, .packages(all.available = TRUE)) ) {
        install.packages(lib)
      }
      library(lib,character.only = TRUE)
    }
  }
  
  libra&lt;-list("foreach","parallel","doSNOW","bigmemory")
  libs(libra)
  
  #create a matrix of size 1GB aproximatelly
  c&lt;-matrix(runif(10000^2),10000,10000)
  #convert it to bigmatrix
  x&lt;-as.big.matrix(c)
  # get a description of the matrix
  mdesc &lt;- describe(x)
  # Create the required connections    
  cl &lt;- makeCluster(detectCores ())
  registerDoSNOW(cl)
  out&lt;-foreach(linID = 1:10, .combine=c) %dopar% {
    #load bigmemory
    require(bigmemory)
    # attach the matrix via shared memory??
    m &lt;- attach.big.matrix(mdesc)
    #dummy expression to test data aquisition
    c&lt;-m[1,1]
  }
  closeAllConnections()
  </code></pre>
  
  <p>RAM:
  <a href="https://i.stack.imgur.com/lsbi5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/lsbi5.png" alt="Ram usage during &lt;code&gt;foreach&lt;/code&gt;"></a>
  in the image above, you may find that the memory increases a lot until <code>foreach</code> ends and it is freed.</p>