📄 reduce.cc
字号:
Ref<GlobalMsgIter> i(topology_->global_msg_iter(this, (target== -1?0:target))); for (i->backwards(); !i->done(); i->next()) { for (int idat=0; idat<n; idat+=tgop_max) { int ndat = (idat+tgop_max>n)?(n-idat):tgop_max; if (i->send()) { send(i->sendto(), &data[idat], ndat); } if (i->recv()) { recv(i->recvfrom(), scratch, ndat); red.reduce(&data[idat], scratch, ndat); } } if (n > tgop_max) sync(); } if (target == -1) { bcast(data, n, 0); } if (!passed_scratch) delete[] scratch;}voidMessageGrp::reduce(int* data, int n, GrpReduce<int>& red, int* scratch, int target){ int tgop_max = gop_max_/sizeof(int); if (tgop_max == 0) tgop_max = gop_max_?1:n; int passed_scratch; if (!scratch) { scratch = new int[n>tgop_max?tgop_max:n]; passed_scratch = 0; } else passed_scratch = 1; Ref<GlobalMsgIter> i(topology_->global_msg_iter(this, (target== -1?0:target))); for (i->backwards(); !i->done(); i->next()) { for (int idat=0; idat<n; idat+=tgop_max) { int ndat = (idat+tgop_max>n)?(n-idat):tgop_max; if (i->send()) { send(i->sendto(), &data[idat], ndat); } if (i->recv()) { recv(i->recvfrom(), scratch, ndat); red.reduce(&data[idat], scratch, ndat); } } if (n > tgop_max) sync(); } if (target == -1) { bcast(data, n, 0); } if (!passed_scratch) delete[] scratch;}voidMessageGrp::reduce(char* data, int n, GrpReduce<char>& red, char* scratch, int target){ int tgop_max = gop_max_/sizeof(char); if (tgop_max == 0) tgop_max = gop_max_?1:n; int passed_scratch; if (!scratch) { scratch = new char[n>tgop_max?tgop_max:n]; passed_scratch = 0; } else passed_scratch = 1; Ref<GlobalMsgIter> i(topology_->global_msg_iter(this, (target== -1?0:target))); for (i->backwards(); !i->done(); i->next()) { for (int idat=0; idat<n; idat+=tgop_max) { int ndat = (idat+tgop_max>n)?(n-idat):tgop_max; if (i->send()) { send(i->sendto(), &data[idat], ndat); } if (i->recv()) { recv(i->recvfrom(), scratch, ndat); red.reduce(&data[idat], scratch, ndat); } } if (n > tgop_max) sync(); } if (target == -1) { bcast(data, n, 0); } if (!passed_scratch) delete[] scratch;}voidMessageGrp::reduce(unsigned char* data, int n, GrpReduce<unsigned char>& red, unsigned char* scratch, int target){ int tgop_max = gop_max_/sizeof(unsigned char); if (tgop_max == 0) tgop_max = gop_max_?1:n; int passed_scratch; if (!scratch) { scratch = new unsigned char[n>tgop_max?tgop_max:n]; passed_scratch = 0; } else passed_scratch = 1; Ref<GlobalMsgIter> i(topology_->global_msg_iter(this, (target== -1?0:target))); for (i->backwards(); !i->done(); i->next()) { for (int idat=0; idat<n; idat+=tgop_max) { int ndat = (idat+tgop_max>n)?(n-idat):tgop_max; if (i->send()) { send(i->sendto(), &data[idat], ndat); } if (i->recv()) { recv(i->recvfrom(), scratch, ndat); red.reduce(&data[idat], scratch, ndat); } } if (n > tgop_max) sync(); } if (target == -1) { bcast(data, n, 0); } if (!passed_scratch) delete[] scratch;}voidMessageGrp::reduce(signed char* data, int n, GrpReduce<signed char>& red, signed char* scratch, int target){ int tgop_max = gop_max_/sizeof(signed char); if (tgop_max == 0) tgop_max = gop_max_?1:n; int passed_scratch; if (!scratch) { scratch = new signed char[n>tgop_max?tgop_max:n]; passed_scratch = 0; } else passed_scratch = 1; Ref<GlobalMsgIter> i(topology_->global_msg_iter(this, (target== -1?0:target))); for (i->backwards(); !i->done(); i->next()) { for (int idat=0; idat<n; idat+=tgop_max) { int ndat = (idat+tgop_max>n)?(n-idat):tgop_max; if (i->send()) { send(i->sendto(), &data[idat], ndat); } if (i->recv()) { recv(i->recvfrom(), scratch, ndat); red.reduce(&data[idat], scratch, ndat); } } if (n > tgop_max) sync(); } if (target == -1) { bcast(data, n, 0); } if (!passed_scratch) delete[] scratch;}voidMessageGrp::reduce(short* data, int n, GrpReduce<short>& red, short* scratch, int target){ int tgop_max = gop_max_/sizeof(short); if (tgop_max == 0) tgop_max = gop_max_?1:n; int passed_scratch; if (!scratch) { scratch = new short[n>tgop_max?tgop_max:n]; passed_scratch = 0; } else passed_scratch = 1; Ref<GlobalMsgIter> i(topology_->global_msg_iter(this, (target== -1?0:target))); for (i->backwards(); !i->done(); i->next()) { for (int idat=0; idat<n; idat+=tgop_max) { int ndat = (idat+tgop_max>n)?(n-idat):tgop_max; if (i->send()) { send(i->sendto(), &data[idat], ndat); } if (i->recv()) { recv(i->recvfrom(), scratch, ndat); red.reduce(&data[idat], scratch, ndat); } } if (n > tgop_max) sync(); } if (target == -1) { bcast(data, n, 0); } if (!passed_scratch) delete[] scratch;}voidMessageGrp::reduce(float* data, int n, GrpReduce<float>& red, float* scratch, int target){ int tgop_max = gop_max_/sizeof(float); if (tgop_max == 0) tgop_max = gop_max_?1:n; int passed_scratch; if (!scratch) { scratch = new float[n>tgop_max?tgop_max:n]; passed_scratch = 0; } else passed_scratch = 1; Ref<GlobalMsgIter> i(topology_->global_msg_iter(this, (target== -1?0:target))); for (i->backwards(); !i->done(); i->next()) { for (int idat=0; idat<n; idat+=tgop_max) { int ndat = (idat+tgop_max>n)?(n-idat):tgop_max; if (i->send()) { send(i->sendto(), &data[idat], ndat); } if (i->recv()) { recv(i->recvfrom(), scratch, ndat); red.reduce(&data[idat], scratch, ndat); } } if (n > tgop_max) sync(); } if (target == -1) { bcast(data, n, 0); } if (!passed_scratch) delete[] scratch;}voidMessageGrp::reduce(long* data, int n, GrpReduce<long>& red, long* scratch, int target){ int tgop_max = gop_max_/sizeof(long); if (tgop_max == 0) tgop_max = gop_max_?1:n; int passed_scratch; if (!scratch) { scratch = new long[n>tgop_max?tgop_max:n]; passed_scratch = 0; } else passed_scratch = 1; Ref<GlobalMsgIter> i(topology_->global_msg_iter(this, (target== -1?0:target))); for (i->backwards(); !i->done(); i->next()) { for (int idat=0; idat<n; idat+=tgop_max) { int ndat = (idat+tgop_max>n)?(n-idat):tgop_max; if (i->send()) { send(i->sendto(), &data[idat], ndat); } if (i->recv()) { recv(i->recvfrom(), scratch, ndat); red.reduce(&data[idat], scratch, ndat); } } if (n > tgop_max) sync(); } if (target == -1) { bcast(data, n, 0); } if (!passed_scratch) delete[] scratch;}#ifdef EXPLICIT_TEMPLATE_INSTANTIATION#define INSTANTIATE_DO_X(func,type) \ template void func(MessageGrp*, type *, int, type *, int)INSTANTIATE_DO_X(do_sum,unsigned int);INSTANTIATE_DO_X(do_sum,int);INSTANTIATE_DO_X(do_sum,double);INSTANTIATE_DO_X(do_sum,char);INSTANTIATE_DO_X(do_sum,unsigned char);INSTANTIATE_DO_X(do_sum,signed char);INSTANTIATE_DO_X(do_max,unsigned int);INSTANTIATE_DO_X(do_max,int);INSTANTIATE_DO_X(do_max,double);INSTANTIATE_DO_X(do_max,char);INSTANTIATE_DO_X(do_max,unsigned char);INSTANTIATE_DO_X(do_max,signed char);INSTANTIATE_DO_X(do_min,unsigned int);INSTANTIATE_DO_X(do_min,int);INSTANTIATE_DO_X(do_min,double);INSTANTIATE_DO_X(do_min,char);INSTANTIATE_DO_X(do_min,unsigned char);INSTANTIATE_DO_X(do_min,signed char);#endif/////////////////////////////////////////////////////////////////////////////// Local Variables:// mode: c++// c-file-style: "CLJ"// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -