📄 reduce.cc
字号:
//// reduce.cc//// Copyright (C) 1996 Limit Point Systems, Inc.//// Author: Curtis Janssen <cljanss@limitpt.com>// Maintainer: LPS//// This file is part of the SC Toolkit.//// The SC Toolkit is free software; you can redistribute it and/or modify// it under the terms of the GNU Library General Public License as published by// the Free Software Foundation; either version 2, or (at your option)// any later version.//// The SC Toolkit is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU Library General Public License for more details.//// You should have received a copy of the GNU Library General Public License// along with the SC Toolkit; see the file COPYING.LIB. If not, write to// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.//// The U.S. Government is granted a limited license as per AL 91-7.//#ifdef HAVE_CONFIG_H#include <scconfig.h>#endif#include <util/group/message.h>using namespace sc;/////////////////////////////////////////////////////////////////////////// instantiate templates#ifdef EXPLICIT_TEMPLATE_INSTANTIATIONtemplate class GrpReduce<double>;template class GrpReduce<unsigned int>;template class GrpReduce<int>;template class GrpReduce<long>;template class GrpReduce<float>;template class GrpReduce<short>;template class GrpReduce<char>;template class GrpReduce<unsigned char>;template class GrpReduce<signed char>;template class GrpFunctionReduce<double>;template class GrpFunctionReduce<unsigned int>;template class GrpFunctionReduce<int>;template class GrpFunctionReduce<long>;template class GrpFunctionReduce<float>;template class GrpFunctionReduce<short>;template class GrpFunctionReduce<char>;template class GrpFunctionReduce<unsigned char>;template class GrpFunctionReduce<signed char>;template class GrpMinReduce<double>;template class GrpMinReduce<unsigned int>;template class GrpMinReduce<int>;template class GrpMinReduce<long>;template class GrpMinReduce<float>;template class GrpMinReduce<short>;template class GrpMinReduce<char>;template class GrpMinReduce<unsigned char>;template class GrpMinReduce<signed char>;template class GrpMaxReduce<double>;template class GrpMaxReduce<unsigned int>;template class GrpMaxReduce<int>;template class GrpMaxReduce<long>;template class GrpMaxReduce<float>;template class GrpMaxReduce<short>;template class GrpMaxReduce<char>;template class GrpMaxReduce<unsigned char>;template class GrpMaxReduce<signed char>;template class GrpSumReduce<double>;template class GrpSumReduce<unsigned int>;template class GrpSumReduce<int>;template class GrpSumReduce<long>;template class GrpSumReduce<float>;template class GrpSumReduce<short>;template class GrpSumReduce<char>;template class GrpSumReduce<unsigned char>;template class GrpSumReduce<signed char>;template class GrpProductReduce<double>;template class GrpProductReduce<unsigned int>;template class GrpProductReduce<int>;template class GrpProductReduce<long>;template class GrpProductReduce<float>;template class GrpProductReduce<short>;template class GrpProductReduce<char>;template class GrpProductReduce<unsigned char>;template class GrpProductReduce<signed char>;template class GrpArithmeticOrReduce<unsigned int>;template class GrpArithmeticOrReduce<int>;template class GrpArithmeticOrReduce<long>;template class GrpArithmeticOrReduce<short>;template class GrpArithmeticOrReduce<char>;template class GrpArithmeticOrReduce<unsigned char>;template class GrpArithmeticOrReduce<signed char>;template class GrpArithmeticAndReduce<unsigned int>;template class GrpArithmeticAndReduce<int>;template class GrpArithmeticAndReduce<long>;template class GrpArithmeticAndReduce<short>;template class GrpArithmeticAndReduce<char>;template class GrpArithmeticAndReduce<unsigned char>;template class GrpArithmeticAndReduce<signed char>;template class GrpArithmeticXOrReduce<unsigned int>;template class GrpArithmeticXOrReduce<int>;template class GrpArithmeticXOrReduce<long>;template class GrpArithmeticXOrReduce<short>;template class GrpArithmeticXOrReduce<char>;template class GrpArithmeticXOrReduce<unsigned char>;template class GrpArithmeticXOrReduce<signed char>;#endif/////////////////////////////////////////////////////////////////////////// sum reduction memberstemplate <class T>voiddo_sum(MessageGrp* grp, T* data, int n, T* tmp, int target){ GrpSumReduce<T> gred; grp->reduce(data, n, gred, tmp, target);}voidMessageGrp::sum(double* data, int n, double* tmp, int target){ do_sum(this, data, n, tmp, target);}voidMessageGrp::sum(unsigned int* data, int n, unsigned int* tmp, int target){ do_sum(this, data, n, tmp, target);}voidMessageGrp::sum(int* data, int n, int* tmp, int target){ do_sum(this, data, n, tmp, target);}voidMessageGrp::sum(char* data, int n, char* tmp, int target){ do_sum(this, data, n, tmp, target);}voidMessageGrp::sum(unsigned char* data, int n, unsigned char* tmp, int target){ do_sum(this, data, n, tmp, target);}voidMessageGrp::sum(signed char* data, int n, signed char* tmp, int target){ do_sum(this, data, n, tmp, target);}/////////////////////////////////////////////////////////////////////////// min reduction memberstemplate <class T>voiddo_max(MessageGrp* grp, T* data, int n, T* tmp, int target){ GrpMaxReduce<T> gred; grp->reduce(data, n, gred, tmp, target);}voidMessageGrp::max(double* data, int n, double* tmp, int target){ do_max(this, data, n, tmp, target);}voidMessageGrp::max(unsigned int* data, int n, unsigned int* tmp, int target){ do_max(this, data, n, tmp, target);}voidMessageGrp::max(int* data, int n, int* tmp, int target){ do_max(this, data, n, tmp, target);}voidMessageGrp::max(char* data, int n, char* tmp, int target){ do_max(this, data, n, tmp, target);}voidMessageGrp::max(unsigned char* data, int n, unsigned char* tmp, int target){ do_max(this, data, n, tmp, target);}voidMessageGrp::max(signed char* data, int n, signed char* tmp, int target){ do_max(this, data, n, tmp, target);}/////////////////////////////////////////////////////////////////////////// max reduction memberstemplate <class T>voiddo_min(MessageGrp* grp, T* data, int n, T* tmp, int target){ GrpMinReduce<T> gred; grp->reduce(data, n, gred, tmp, target);}voidMessageGrp::min(double* data, int n, double* tmp, int target){ do_min(this, data, n, tmp, target);}voidMessageGrp::min(unsigned int* data, int n, unsigned int* tmp, int target){ do_min(this, data, n, tmp, target);}voidMessageGrp::min(int* data, int n, int* tmp, int target){ do_min(this, data, n, tmp, target);}voidMessageGrp::min(char* data, int n, char* tmp, int target){ do_min(this, data, n, tmp, target);}voidMessageGrp::min(unsigned char* data, int n, unsigned char* tmp, int target){ do_min(this, data, n, tmp, target);}voidMessageGrp::min(signed char* data, int n, signed char* tmp, int target){ do_min(this, data, n, tmp, target);}/////////////////////////////////////////////////////////////////////////// generic reductionvoidMessageGrp::reduce(double* data, int n, GrpReduce<double>& red, double* scratch, int target){ int tgop_max = gop_max_/sizeof(double); if (tgop_max == 0) tgop_max = gop_max_?1:n; int passed_scratch; if (!scratch) { scratch = new double[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 int* data, int n, GrpReduce<unsigned int>& red, unsigned int* scratch, int target){ int tgop_max = gop_max_/sizeof(unsigned int); if (tgop_max == 0) tgop_max = gop_max_?1:n; int passed_scratch; if (!scratch) { scratch = new unsigned int[n>tgop_max?tgop_max:n]; passed_scratch = 0; } else passed_scratch = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -