• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision4e91aae83ea0476ef7112e00d6fe2b9a5031574c (tree)
Time2013-07-12 15:59:42
AuthorMikiya Fujii <mikiya.fujii@gmai...>
CommiterMikiya Fujii

Log Message

Too big messages are split to be send by MPI. #31588

git-svn-id: https://svn.sourceforge.jp/svnroot/molds/branches/mpi-cis@1388 1136aad2-a195-0410-b898-f5ea1d11b9d8

Change Summary

Incremental Difference

--- a/src/mpi/MpiProcess.cpp
+++ b/src/mpi/MpiProcess.cpp
@@ -37,6 +37,7 @@ MpiProcess::MpiProcess(){
3737 MpiProcess::MpiProcess(int argc, char *argv[]){
3838 this->environment = new boost::mpi::environment(argc, argv);
3939 this->communicator = new boost::mpi::communicator();
40+ this->messageLimit = INT_MAX;
4041 }
4142
4243 MpiProcess::~MpiProcess(){
--- a/src/mpi/MpiProcess.h
+++ b/src/mpi/MpiProcess.h
@@ -18,9 +18,9 @@
1818 //************************************************************************//
1919 #ifndef INCLUDED_MPIPROCESS
2020 #define INCLUDED_MPIPROCESS
21+#include<limits.h>
2122 #include<boost/mpi.hpp>
2223 namespace MolDS_mpi{
23-
2424 // MpiProcess is singleton
2525 class MpiProcess: private MolDS_base::Uncopyable{
2626 public:
@@ -29,9 +29,28 @@ public:
2929 static MpiProcess* GetInstance();
3030 int GetRank() const{return this->communicator->rank();}
3131 int GetSize() const{return this->communicator->size();}
32- template<typename T> void Send(int dest, int tag, const T* values, int n) const{this->communicator->send(dest, tag, values, n);}
33- template<typename T> void Recv(int source, int tag, T* values, int n) const{this->communicator->recv(source, tag, values, n);}
34- template<typename T> void Broadcast(T* values, int n, int root) const{broadcast(*this->communicator, values, n, root);}
32+ template<typename T> void Send(int dest, int tag, const T* values, intptr_t num) const{
33+ std::vector<Chunk> chunks;
34+ this->SplitMessage2Chunks(chunks, tag, values, num);
35+ for(intptr_t i=0; i<chunks.size(); i++){
36+ this->communicator->send(dest, chunks[i].tag, &values[chunks[i].first], chunks[i].num);
37+ }
38+ }
39+ template<typename T> void Recv(int source, int tag, T* values, intptr_t num) const{
40+ std::vector<Chunk> chunks;
41+ this->SplitMessage2Chunks(chunks, tag, values, num);
42+ for(intptr_t i=0; i<chunks.size(); i++){
43+ this->communicator->recv(source, chunks[i].tag, &values[chunks[i].first], chunks[i].num);
44+ }
45+ }
46+ template<typename T> void Broadcast(T* values, intptr_t num, int root) const{
47+ std::vector<Chunk> chunks;
48+ intptr_t tag=0;
49+ this->SplitMessage2Chunks(chunks, tag, values, num);
50+ for(intptr_t i=0; i<chunks.size(); i++){
51+ broadcast(*this->communicator, &values[chunks[i].first], chunks[i].num, root);
52+ }
53+ }
3554 private:
3655 static MpiProcess* mpiProcess;
3756 MpiProcess();
@@ -39,6 +58,31 @@ private:
3958 ~MpiProcess();
4059 boost::mpi::environment* environment;
4160 boost::mpi::communicator* communicator;
61+ struct Chunk{int tag; intptr_t first; int num;};
62+ double messageLimit;
63+ template<typename T> void SplitMessage2Chunks(std::vector<Chunk>& chunks, const int origianlTag, T* values, intptr_t num) const{
64+ if(this->messageLimit < static_cast<double>(sizeof(T))*static_cast<double>(num) ){
65+ int elementsLimit = static_cast<intptr_t>(messageLimit/sizeof(T));
66+ intptr_t numChunks = num/elementsLimit;
67+ int remaining = num%elementsLimit;
68+ if(0 < remaining){
69+ numChunks++;
70+ }
71+ int tagBase = origianlTag*numChunks;
72+ for(intptr_t i=0; i<numChunks; i++){
73+ int tag = tagBase+i;
74+ Chunk chunk = {tag, i*elementsLimit, elementsLimit};
75+ chunks.push_back(chunk);
76+ }
77+ if(0 < remaining){
78+ chunks[numChunks-1].num = remaining;
79+ }
80+ }
81+ else{
82+ Chunk chunk = {origianlTag, 0, num};
83+ chunks.push_back(chunk);
84+ }
85+ }
4286 };
4387
4488 }