|
RInside Version 0.2.6
|
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*- 00002 // 00003 // Simple example showing in R console information about current node 00004 // 00005 // MPI C++ API version of file contributed by Jianping Hua 00006 // 00007 // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois 00008 // 00009 // GPL'ed 00010 00011 #include <mpi.h> // mpi header 00012 #include <RInside.h> // for the embedded R via RInside 00013 00014 int main(int argc, char *argv[]) { 00015 00016 MPI::Init(argc, argv); // mpi initialization 00017 int myrank = MPI::COMM_WORLD.Get_rank(); // obtain current node rank 00018 int nodesize = MPI::COMM_WORLD.Get_size(); // obtain total nodes running. 00019 00020 RInside R(argc, argv); // create an embedded R instance 00021 00022 std::stringstream txt; 00023 txt << "Hello from node " << myrank // node information 00024 << " of " << nodesize << " nodes!" << std::endl; 00025 00026 R["txt"] = txt.str(); // assign string var to R variable 'txt' 00027 00028 R.parseEvalQ("cat(txt)"); // eval init string, ignoring any returns 00029 00030 MPI::Finalize(); // mpi finalization 00031 00032 exit(0); 00033 }