00001
00007 #include "EachToManyMulticastStrategy.h"
00008 #include "string.h"
00009
00010 #include "AAPLearner.h"
00011 #include "AAMLearner.h"
00012
00013
00014
00015 EachToManyMulticastStrategy::EachToManyMulticastStrategy(int substrategy,
00016 CkGroupID src,
00017 CkGroupID dest,
00018 int n_srcpes,
00019 int *src_pelist,
00020 int n_destpes,
00021 int *dest_pelist)
00022 : RouterStrategy(substrategy), CharmStrategy() {
00023 ComlibPrintf("[%d] EachToManyMulticast group constructor\n",CkMyPe());
00024
00025 setType(GROUP_STRATEGY);
00026
00027
00028
00029 ginfo.setSourceGroup(src, src_pelist, n_srcpes);
00030 ginfo.setDestinationGroup(dest, dest_pelist, n_destpes);
00031
00032
00033
00034
00035
00036 commonInit(ginfo.getCombinedCountList());
00037 }
00038
00039
00040 EachToManyMulticastStrategy::EachToManyMulticastStrategy(int substrategy,
00041 CkArrayID src,
00042 CkArrayID dest,
00043 int nsrc,
00044 CkArrayIndex *srcelements,
00045 int ndest,
00046 CkArrayIndex *destelements)
00047 : RouterStrategy(substrategy), CharmStrategy() {
00048 ComlibPrintf("[%d] EachToManyMulticast array constructor. nsrc=%d ndest=%d\n",CkMyPe(), nsrc, ndest);
00049
00050 setType(ARRAY_STRATEGY);
00051 ainfo.setSourceArray(src, srcelements, nsrc);
00052 ainfo.setDestinationArray(dest, destelements, ndest);
00053
00054 int *count = ainfo.getCombinedCountList();
00055
00056
00057
00058 commonInit(count);
00059 }
00060
00061 extern char *routerName;
00062
00063 void EachToManyMulticastStrategy::commonInit(int *count) {
00064
00065 setBracketed();
00066
00067
00068 if(CkMyPe() == 0 && routerName != NULL){
00069 if(strcmp(routerName, "USE_MESH") == 0)
00070 routerIDsaved = USE_MESH;
00071 else if(strcmp(routerName, "USE_GRID") == 0)
00072 routerIDsaved = USE_GRID;
00073 else if(strcmp(routerName, "USE_HYPERCUBE") == 0)
00074 routerIDsaved = USE_HYPERCUBE;
00075 else if(strcmp(routerName, "USE_DIRECT") == 0)
00076 routerIDsaved = USE_DIRECT;
00077 else if(strcmp(routerName, "USE_PREFIX") == 0)
00078 routerIDsaved = USE_PREFIX;
00079
00080
00081
00082
00083 }
00084
00085
00086
00087
00088 bracketedUpdatePeKnowledge(count);
00089 delete [] count;
00090
00091 }
00092
00093 EachToManyMulticastStrategy::~EachToManyMulticastStrategy() {
00094 }
00095
00096
00097 void EachToManyMulticastStrategy::insertMessage(CharmMessageHolder *cmsg){
00098
00099
00100
00101 ComlibPrintf("[%d] EachToManyMulticast: insertMessage\n", CkMyPe());
00102
00103 envelope *env = UsrToEnv(cmsg->getCharmMessage());
00104
00105 if(cmsg->dest_proc == IS_BROADCAST) {
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 CmiSetHandler(env, CkpvAccess(comlib_handler));
00118
00119
00120 RECORD_SENDM_STATS(getInstance(), env->getTotalsize(),
00121 cmsg->pelist, cmsg->npes);
00122 }
00123 else {
00124
00125
00126
00127 RECORD_SEND_STATS(getInstance(), env->getTotalsize(),
00128 cmsg->dest_proc);
00129 }
00130
00131 RouterStrategy::insertMessage(cmsg);
00132 }
00133
00134
00135 void EachToManyMulticastStrategy::pup(PUP::er &p){
00136
00137 ComlibPrintf("[%d] EachToManyMulticastStrategy::pup called for %s\n", CkMyPe(),
00138 p.isPacking()?"packing":(p.isUnpacking()?"unpacking":"sizing"));
00139
00140 RouterStrategy::pup(p);
00141 CharmStrategy::pup(p);
00142
00143 }
00144
00145
00146
00147 void EachToManyMulticastStrategy::deliver(char *msg, int size) {
00148 ComlibPrintf("[%d] EachToManyMulticastStrategy::deliver for %s\n",
00149 CkMyPe(), isAllToAll()?"multicast":"personalized");
00150
00151 envelope *env = (envelope *)msg;
00152 RECORD_RECV_STATS(myHandle, env->getTotalsize(), env->getSrcPe());
00153
00154 if (isAllToAll()){
00155 ComlibPrintf("Delivering via localMulticast()\n");
00156 localMulticast(msg);
00157 }
00158 else {
00159 if (getType() == GROUP_STRATEGY) {
00160 ComlibPrintf("Delivering via personalized CkSendMsgBranchInline\n");
00161 CkUnpackMessage(&env);
00162 CkSendMsgBranchInline(env->getEpIdx(), EnvToUsr(env), CkMyPe(), env->getGroupNum());
00163 }
00164 else if (getType() == ARRAY_STRATEGY) {
00165
00166
00167
00168 ComlibPrintf("[%d] Delivering via ComlibArrayInfo::localBroadcast()\n", CkMyPe());
00169 ainfo.localBroadcast(env);
00170
00171 }
00172 }
00173 }
00174
00175 void EachToManyMulticastStrategy::localMulticast(void *msg){
00176 register envelope *env = (envelope *)msg;
00177 CkUnpackMessage(&env);
00178 ComlibPrintf("localMulticast calls ainfo.localBroadcast()\n");
00179 ainfo.localBroadcast(env);
00180 }
00181
00182 void EachToManyMulticastStrategy::notifyDone() {
00183 if (!getOnFinish().isInvalid()) getOnFinish().send(0);
00184 RouterStrategy::notifyDone();
00185 }
00186