RInside Version 0.2.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rinside_mpi_sample2.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 // MPI C++ API version of file contributed by Jianping Hua
6 //
7 // Copyright (C) 2010 - 2011 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::Init(argc, argv); // mpi initialization
17  int myrank = MPI::COMM_WORLD.Get_rank(); // obtain current node rank
18  int nodesize = MPI::COMM_WORLD.Get_size(); // obtain total nodes running.
19 
20  RInside R(argc, argv); // create an embedded R instance
21 
22  std::stringstream txt;
23  txt << "Hello from node " << myrank // node information
24  << " of " << nodesize << " nodes!" << std::endl;
25 
26  R["txt"] = txt.str(); // assign string var to R variable 'txt'
27 
28  R.parseEvalQ("cat(txt)"); // eval init string, ignoring any returns
29 
30  MPI::Finalize(); // mpi finalization
31 
32  exit(0);
33 }
void parseEvalQ(const std::string &line)
Definition: RInside.cpp:366
int main(int argc, char *argv[])