title: compiling an OpenMPI app with the Intel compiler suite
body: <p>I have the latest OpenMPI on linux which I compiled with the Intel compiler suite. I am trying to compile an OpenMPI application. My particular application uses RInside and RcppEigen. If I comment out the openMPI parts of my code, the compile string is:</p>
  
  <pre><code>icpc -I/usr/share/R/include -I/usr/lib/R/site-library/Rcpp/include -I/usr/local/lib/R/site-library/RInside/include -O3 -pipe -g -Wall  -I/usr/local/lib/R/site-library/RcppEigen/include   sjb_simple_smle_with_Rinside.cpp  -L/usr/lib/R/lib -lR  -lblas -llapack -L/usr/lib/R/site-library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/lib/R/site-library/Rcpp/lib -L/usr/local/lib/R/site-library/RInside/lib -lRInside -Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib  -o sjb_simple_smle_with_Rinside
  </code></pre>
  
  <p>Thus, I tried to compile with mpic++ using:</p>
  
  <blockquote>
    <p>mpic++ -I/usr/share/R/include -I/usr/lib/R/site-library/Rcpp/include
    -I/usr/local/lib/R/site-library/RInside/include -O3 -pipe -g -Wall  -I/usr/local/lib/R/site-library/RcppEigen/include   sjb_simple_smle_with_Rinside.cpp  -L/usr/lib/R/lib -lR  -lblas
    -llapack -L/usr/lib/R/site-library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/lib/R/site-library/Rcpp/lib -L/usr/local/lib/R/site-library/RInside/lib -lRInside -Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib  -o sjb_simple_smle_with_Rinside</p>
  </blockquote>
  
  <p>If I uncomment</p>
  
  <pre><code>#include "mpi.h"
  </code></pre>
  
  <p>and try to compile, I get the errors below. Is there any trick to compiling OpenMPI applications with the Intel compilers? The full source is listed below:</p>
  
  <pre><code>stevejb@ursamajor:~/Projects/big_data_sim_mle/simple_smle/R_inside_version$ mpic++ -I/usr/share/R/include -I/usr/lib/R/site-library/Rcpp/include -I/usr/local/lib/R/site-library/RInside/include -O3 -pipe -g -Wall -I/usr/local/lib/R/site-library/RcppEigen/include sjb_simple_smle_with_Rinside.cpp -L/usr/lib/R/lib -lR -lblas -llapack -L/usr/lib/R/site-library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/lib/R/site-library/Rcpp/lib -L/usr/local/lib/R/site-library/RInside/lib -lRInside -Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib -o sjb_simple_smle_with_Rinside -shared-intel -I/usr/local/include -pthread -L/usr/local/lib -lmpi_cxx -lmpi -ldl -lm -Wl,--export-dynamic -lrt -lnsl -lutil
  /usr/local/include/openmpi/ompi/mpi/cxx/datatype.h(142): error: expected a type specifier
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/datatype.h(142): error: expected a ")"
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/datatype.h(142): error: expected an identifier
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/datatype.h(142): error: "virtual" is not allowed
      virtual void Free();
      ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/datatype.h(142): error: expected a ";"
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/op.h(48): error: expected a type specifier
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/op.h(48): error: expected a ")"
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/op.h(48): error: expected an identifier
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/op.h(48): error: "virtual" is not allowed
      virtual void Free();
      ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/op.h(48): error: expected a ";"
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/request.h(96): error: expected a type specifier
      virtual void Free(void);
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/request.h(96): error: expected a ")"
      virtual void Free(void);
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/request.h(96): error: expected an identifier
      virtual void Free(void);
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/request.h(96): error: "virtual" is not allowed
      virtual void Free(void);
      ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/request.h(96): error: expected a ";"
      virtual void Free(void);
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/group.h(111): error: expected a type specifier
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/group.h(111): error: expected a ")"
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/group.h(111): error: expected an identifier
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/group.h(111): error: "virtual" is not allowed
      virtual void Free();
      ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/group.h(111): error: expected a ";"
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/comm.h(264): error: expected a type specifier
      virtual void Free(void);
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/comm.h(264): error: expected a ")"
      virtual void Free(void);
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/comm.h(264): error: expected an identifier
      virtual void Free(void);
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/comm.h(264): error: "virtual" is not allowed
      virtual void Free(void);
      ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/comm.h(264): error: expected a ";"
      virtual void Free(void);
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/win.h(118): error: expected a type specifier
      virtual void Free(); 
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/win.h(118): error: expected a ")"
      virtual void Free(); 
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/win.h(118): error: expected an identifier
      virtual void Free(); 
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/win.h(118): error: "virtual" is not allowed
      virtual void Free(); 
      ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/win.h(118): error: expected a ";"
      virtual void Free(); 
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/errhandler.h(59): error: expected a type specifier
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/errhandler.h(59): error: expected a ")"
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/errhandler.h(59): error: expected an identifier
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/errhandler.h(59): error: "virtual" is not allowed
      virtual void Free();
      ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/errhandler.h(59): error: expected a ";"
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/info.h(84): error: expected a type specifier
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/info.h(84): error: expected a ")"
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/info.h(84): error: expected an identifier
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/info.h(84): error: "virtual" is not allowed
      virtual void Free();
      ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/info.h(84): error: expected a ";"
      virtual void Free();
                   ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/request_inln.h(39): error: expected an identifier
    MPI::Request::Free() 
                  ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/request_inln.h(38): error: inline specifier allowed on function declarations only
    inline void
    ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/request_inln.h(39): error: incomplete type is not allowed
    MPI::Request::Free() 
                  ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/request_inln.h(39): error: a nonstatic member reference must be relative to a specific object
    MPI::Request::Free() 
                  ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/request_inln.h(39): error: expected an expression
    MPI::Request::Free() 
                  ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/request_inln.h(39): error: expected a ")"
    MPI::Request::Free() 
                  ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/request_inln.h(40): error: expected a ";"
    {
    ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/op_inln.h(123): error: identifier "ompi_op_set_cxx_callback" is undefined
        ompi_op_set_cxx_callback(mpi_op, (MPI_User_function*) func);
        ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/op_inln.h(128): error: expected an identifier
    MPI::Op::Free()
             ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/op_inln.h(127): error: inline specifier allowed on function declarations only
    inline void
    ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/op_inln.h(128): error: incomplete type is not allowed
    MPI::Op::Free()
             ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/op_inln.h(128): error: a nonstatic member reference must be relative to a specific object
    MPI::Op::Free()
             ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/op_inln.h(128): error: expected an expression
    MPI::Op::Free()
             ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/op_inln.h(128): error: expected a ")"
    MPI::Op::Free()
             ^
  
  /usr/local/include/openmpi/ompi/mpi/cxx/op_inln.h(129): error: expected a ";"
    {
    ^
  
  sjb_simple_smle_with_Rinside.cpp(35): warning #12: parsing restarts here after previous syntax error
    using namespace Rcpp;
                        ^
  
  sjb_simple_smle_with_Rinside.cpp(77): error: identifier "as" is undefined
      const Map&lt;MatrixXd&gt; Xmat(as&lt;Map&lt;MatrixXd&gt; &gt;(Xmat_sexp));
                               ^
  
  sjb_simple_smle_with_Rinside.cpp(77): error: type name is not allowed
      const Map&lt;MatrixXd&gt; Xmat(as&lt;Map&lt;MatrixXd&gt; &gt;(Xmat_sexp));
                                  ^
  
  sjb_simple_smle_with_Rinside.cpp(80): error: type name is not allowed
      const Map&lt;MatrixXd&gt; Ymat(as&lt;Map&lt;MatrixXd&gt; &gt;(Ymat_sexp));
                                  ^
  
  sjb_simple_smle_with_Rinside.cpp(87): error: type name is not allowed
      const Map&lt;MatrixXd&gt; ua(as&lt;Map&lt;MatrixXd&gt; &gt;(ua_sexp));
                                ^
  
  sjb_simple_smle_with_Rinside.cpp(89): error: type name is not allowed
      const Map&lt;MatrixXd&gt; ub(as&lt;Map&lt;MatrixXd&gt; &gt;(ub_sexp));
                                ^
  
  sjb_simple_smle_with_Rinside.cpp(98): error: type name is not allowed
      const Map&lt;VectorXd&gt; start_vector(as&lt;Map&lt;VectorXd&gt; &gt;(start_sexp));
                                          ^
  
  compilation aborted for sjb_simple_smle_with_Rinside.cpp (code 2)
  </code></pre>
  
  <p>FULL SOURCE CODE:</p>
  
  <pre><code>// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
  //
  // SJB - first shot at RInside and Eigen combined
  //
  // Copyright (C) 2012             Stephen J. Barr
  //
  // GPL'ed 
  
  
  #include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;iomanip&gt;
  #include &lt;fstream&gt;
  #include "mkl.h"
  #include "math.h"
  #include &lt;vector&gt;
  #include &lt;cmath&gt;
  #include &lt;string&gt;
  #include &lt;cstdlib&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;getopt.h&gt;
  #include &lt;map&gt;
  #include &lt;utility&gt;
  
  #include &lt;RcppEigen.h&gt;
  #include &lt;Rcpp.h&gt;
  #include &lt;RInside.h&gt;                            // for the embedded R via RInside
  #include "mpi.h"
  
  using namespace Rcpp;
  using namespace Eigen;
  using namespace std;
  int main(int argc, char *argv[]) {
  
  
    const int N_TRU_PARAMS = 5;
    const int n = 1000;
    const int t = 100;
    const int nr = 500;
  
    RInside R(argc, argv);                      // create an embedded R instance 
  
    stringstream ss;
    ss &lt;&lt; "n = " &lt;&lt; n &lt;&lt; "; t = " &lt;&lt; t &lt;&lt; ";" &lt;&lt; " nr = " &lt;&lt; nr &lt;&lt; ";";
    cout &lt;&lt; ss.str() &lt;&lt; endl;
    R.parseEval(ss.str());
  
    VectorXd tru = VectorXd(N_TRU_PARAMS);
    tru &lt;&lt; 2,1,-2,1,1;
  
    // R.parseEval("n = 100;");
    // R.parseEval("t = 100;");
    R.parseEval("set.seed(123)");
    string cmdstr = "tru = c(2,1,-2,1,1);"
                     "set.seed(123);"
                     "a = rnorm(n,tru[1],tru[2]);"
                     "b = rnorm(n,tru[3],tru[4]);"           
      //             Make some data lists   
                     "x = NULL;"
                     "y = NULL;"
  
      //             Generate some data for each firm
                     "for(i in 1:n) {"
                     "  x[[i]] = rnorm(t,1,1);"
                     "  y[[i]] = a[i]+b[i]*x[[i]]+ rnorm(t)*tru[5];"
      "}";
  
  
    R.parseEval(cmdstr);
  
    SEXP Xmat_sexp = R.parseEval("Xmat = do.call(rbind, x)");
    const Map&lt;MatrixXd&gt; Xmat(as&lt;Map&lt;MatrixXd&gt; &gt;(Xmat_sexp));
  
    SEXP Ymat_sexp = R.parseEval("Ymat = do.call(rbind, y)");
    const Map&lt;MatrixXd&gt; Ymat(as&lt;Map&lt;MatrixXd&gt; &gt;(Ymat_sexp));
  
    cout &lt;&lt; "X: " &lt;&lt; Xmat.rows() &lt;&lt; " x " &lt;&lt; Xmat.cols() &lt;&lt; endl;
    cout &lt;&lt; "Y: " &lt;&lt; Ymat.rows() &lt;&lt; " x " &lt;&lt; Ymat.cols() &lt;&lt; endl;
  
    // Make matrices ua and ub
    SEXP ua_sexp = R.parseEval(    "ua = matrix(rnorm(nr*n),n,nr)");
    const Map&lt;MatrixXd&gt; ua(as&lt;Map&lt;MatrixXd&gt; &gt;(ua_sexp));
    SEXP ub_sexp = R.parseEval(    "ub = matrix(rnorm(nr*n),n,nr)");
    const Map&lt;MatrixXd&gt; ub(as&lt;Map&lt;MatrixXd&gt; &gt;(ub_sexp));
  
    cmdstr = "track = 0;"
      "Y = unlist(y);"
      "X = unlist(x);"
      "start = lm(Y~X)$coeff;"
      "start =c(start[1],0,start[2],0);";
    R.parseEval(cmdstr);
    SEXP start_sexp = R.parseEval("start");
    const Map&lt;VectorXd&gt; start_vector(as&lt;Map&lt;VectorXd&gt; &gt;(start_sexp));
  
    cout &lt;&lt; "Starting point: " &lt;&lt; start_vector.transpose() &lt;&lt; endl;
  
    // THERE ARE TWO PAIRS OF FUNCTIONS, smle_init and smle_nll_mpi
    // smle_init: distributes, using mpi broadcast, the necessary
    // data to all machines. 
    // 
    // smle_nll_mpi: assuming smle_init has been successfully completed
    // compute the negative log likelihood using MPI
    // 
  
    // for now, these functions will be written out in the code
  
  
    // // MPI INITIALIZATION
    // int rank, size;
    // const int root = 0;
    // cout &lt;&lt; "Before init" &lt;&lt; endl;
    // MPI::Init();
    // rank = MPI::COMM_WORLD.Get_rank();
    // size = MPI::COMM_WORLD.Get_size();
    // double * ua_ptr = ua.data();
    // double * ub_ptr = ub.data();
  
    cout &lt;&lt; "Initializating MPI Broadcast" &lt;&lt; endl;
  
  
  }
  </code></pre>