RInside Version 0.2.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rinside_mpi_sample0.cpp
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
2 //
3 // Simple example showing in R console information about current node
4 //
5 // This file was contributed by Jianping Hua
6 //
7 // Copyright (C) 2010 - 2011 Jianping Hua, Dirk Eddelbuettel and Romain Francois
8 //
9 // GPL'ed
10 
11 #include <mpi.h> // mpi header
12 #include <RInside.h> // for the embedded R via RInside
13 
14 int main(int argc, char *argv[]) {
15 
16  // mpi related
17  int myrank, nodesize; // node information
18  MPI_Init(&argc,&argv); // mpi initialization
19  MPI_Comm_rank(MPI_COMM_WORLD, &myrank); // obtain current node rank
20  MPI_Comm_size(MPI_COMM_WORLD, &nodesize); // obtain total nodes running.
21 
22  RInside R(argc, argv); // create an embedded R instance
23 
24  std::stringstream txt;
25  txt << "Hello from node " << myrank // node information
26  << " of " << nodesize << " nodes!" << std::endl;
27 
28  R["txt"] = txt.str(); // assign string var to R variable 'txt'
29 
30  R.parseEvalQ("cat(txt)"); // eval init string, ignoring any returns
31 
32  MPI_Finalize(); // mpi finalization
33 
34  exit(0);
35 }
void parseEvalQ(const std::string &line)
Definition: RInside.cpp:366
int main(int argc, char *argv[])