From 31a3d22af433d19fc49113b55b462e13d33c2685 Mon Sep 17 00:00:00 2001 From: tqchen Date: Thu, 1 Jan 2015 05:42:38 -0800 Subject: [PATCH] add broadcast --- guide/broadcast.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 guide/broadcast.cc diff --git a/guide/broadcast.cc b/guide/broadcast.cc new file mode 100644 index 000000000..83dbe67fe --- /dev/null +++ b/guide/broadcast.cc @@ -0,0 +1,16 @@ +#include +using namespace rabit; +const int N = 3; +int main(int argc, char *argv[]) { + rabit::Init(argc, argv); + std::string s; + if (rabit::GetRank() == 0) s = "hello world"; + printf("@node[%d] before-broadcast: s=\"%s\"\n", + rabit::GetRank(), s.c_str()); + // broadcast s from node 0 to all other nodes + rabit::Broadcast(&s, 0); + printf("@node[%d] after-broadcast: s=\"%s\"\n", + rabit::GetRank(), s.c_str()); + rabit::Finalize(); + return 0; +}