size_t VarContainer::varIndex(std::string var_name) { for (int i = 0; i < numVars(); ++i) { if (varName(i) == var_name) return i; } return numVars(); }
ForallIntents* ForallIntents::copy(SymbolMap* map, bool internal) { // If this fails, see localMap and update_symbols() in DECLARE_COPY(). // NB we can't DECLARE_COPY(ForallIntents) because it has _this->astloc. INT_ASSERT(map && internal); // Start would-be copyInner(). ForallIntents* _this = new ForallIntents(); // alas std::vector does not have a constructor that "reserves" slots int nv = numVars(); _this->fiVars.reserve(nv); _this->fIntents.reserve(nv); _this->riSpecs.reserve(nv); for (int i = 0; i < nv; i++) { _this->fiVars .push_back(COPY_INT(fiVars[i])); _this->fIntents.push_back( fIntents[i]); _this->riSpecs .push_back(COPY_INT(riSpecs[i])); } _this->iterRec = COPY_INT(iterRec); _this->leadIdx = COPY_INT(leadIdx); _this->leadIdxCopy = COPY_INT(leadIdxCopy); // Finish would-be copyInner(). // No update_symbols() because !internal is false. return _this; }
T_ State<T_>::decode(const size_t& n, const size_t& i) const { size_t numVars(size()), stride(1u); assert(i < numVars); assert(n < maxConcreteState_); // #pragma omp parallel for reduction (*:stride) shared(i,numVars) for (size_t j = i+1 ; j < numVars ; j++) stride *= pvars_[j]->range_; return pvars_[i]->val((n / stride) % pvars_[i]->range_); }
double LinearFunction::evaluate(double const* x) const { size_t const num_vars = numVars(); double sum = b; for (size_t i = 0; i < num_vars; ++i) { sum += a[i] * x[i]; } return sum; }
size_t State<T_>::encode() const { size_t n(0), numVars(size()); // #pragma omp parallel for reduction(+:n) shared(numVars) for (size_t i=0 ; i < numVars ; i++) { size_t stride(1); for (size_t j = i+1 ; j < numVars; j++) stride *= pvars_[j]->range_; n += pvars_[i]->offset_ * stride; } return n; }
void Message::genDecls(XStr& str) { XStr ptype; ptype<<proxyPrefix()<<type; if(type->isTemplated()) return; str << "/* DECLS: "; print(str); str << " */\n"; if(templat) templat->genSpec(str); str << "class "; type->print(str); str << ";\n"; if(templat) templat->genSpec(str); str << "class "<<ptype; if(external || type->isTemplated()) { str << ";\n"; return; } str << ":public CkMessage"; genAllocDecl(str); if(!(external||type->isTemplated())) { // generate register function str << " static void __register(const char *s, size_t size, CkPackFnPtr pack, CkUnpackFnPtr unpack) {\n"; str << " __idx = CkRegisterMsg(s, pack, unpack, dealloc, size);\n"; str << " }\n"; } str << "};\n"; if (strncmp(type->getBaseName(), "MarshallMsg_", 12) == 0) { MsgVarList *ml; MsgVar *mv; int i; str << "class " << type << " : public " << ptype << " {\n"; str << " public:\n"; int num = numVars(); for(i=0, ml=mvlist; i<num; i++, ml=ml->next) { mv = ml->msg_var; if (mv->isConditional() || mv->isArray()) { str << " /* "; mv->print(str); str << " */\n"; str << " " << mv->type << " *" << mv->name << ";\n"; } } str <<"};\n"; } }
void ForallIntents::verifyFI(BlockStmt* parentB) { Expr* parentE = (Expr*)parentB; int nv = numVars(); INT_ASSERT((int)(fiVars.size()) == nv); INT_ASSERT((int)(fIntents.size()) == nv); INT_ASSERT((int)(riSpecs.size()) == nv); for (int i = 0; i < nv; i++) { Expr* fiVar = fiVars[i]; if (SymExpr* fiVarSE = toSymExpr(fiVar)) { INT_ASSERT(isVarSymbol(fiVarSE->symbol()) || isArgSymbol(fiVarSE->symbol())); // no modules, fns, etc. } else { // fiVars[i] is either resolved or unresolved sym expr; never NULL. INT_ASSERT(isUnresolvedSymExpr(fiVar)); // These should be resolved during scopeResolve. INT_ASSERT(!normalized); } verifyNotOnList(fiVar); INT_ASSERT(fiVar->parentExpr == parentE); Expr* ri = riSpecs[i]; INT_ASSERT(isReduce(i) == !!ri); if (ri) { // ri can be UnresolvedSymExpr, SymExpr, CallExpr, ... (?) verifyNotOnList(ri); INT_ASSERT(ri->parentExpr == parentE); } } INT_ASSERT(!iterRec || iterRec->parentExpr == parentE); INT_ASSERT(!leadIdx || leadIdx->parentExpr == parentE); INT_ASSERT(!leadIdxCopy || leadIdxCopy->parentExpr == parentE); verifyNotOnList(iterRec); verifyNotOnList(leadIdx); verifyNotOnList(leadIdxCopy); // ForallIntents are gone during resolve(). INT_ASSERT(!resolved); }
void Message::genDefs(XStr& str) { int i, count, num = numVars(); int numArray = numArrays(); MsgVarList *ml; MsgVar *mv; XStr ptype, mtype, tspec; ptype<<proxyPrefix()<<type; if(templat) templat->genVars(ptype); mtype << type; if(templat) templat->genVars(mtype); if(templat) { templat->genSpec(tspec); tspec << " "; } str << "/* DEFS: "; print(str); str << " */\n"; templateGuardBegin(templat, str); if(!(external||type->isTemplated())) { // new (size_t) str << tspec << "void *" << ptype << "::operator new(size_t s){\n"; str << " return " << mtype << "::alloc(__idx, s, 0, 0);\n}\n"; // new (size_t, int*) str << tspec << "void *" << ptype << "::operator new(size_t s, int* sz){\n"; str << " return " << mtype << "::alloc(__idx, s, sz, 0);\n}\n"; // new (size_t, int*, priobits) str << tspec << "void *" << ptype << "::operator new(size_t s, int* sz,"; str << "const int pb){\n"; str << " return " << mtype << "::alloc(__idx, s, sz, pb);\n}\n"; // new (size_t, int, int, ..., int) if(numArray>0) { str << tspec << "void *" << ptype << "::operator new(size_t s"; for(i=0;i<numArray;i++) str << ", int sz" << i; str << ") {\n"; str << " int sizes[" << numArray << "];\n"; for(i=0;i<numArray;i++) str << " sizes[" << i << "] = sz" << i << ";\n"; str << " return " << mtype << "::alloc(__idx, s, sizes, 0);\n"; str << "}\n"; } // new (size_t, int, int, ..., int, priobits) // degenerates to new(size_t, priobits) if no varsize std::vector<MsgVar *> arrayVars; str << tspec << "void *"<< ptype << "::operator new(size_t s, "; for(i=0;i<numArray;i++) str << "int sz" << i << ", "; str << "const int p) {\n"; if (numArray>0) { str << " int sizes[" << numArray << "];\n"; for(i=0, count=0, ml=mvlist ;i<num; i++, ml=ml->next) { mv = ml->msg_var; if (mv->isArray()) { str << " sizes[" << count << "] = sz" << count << ";\n"; count ++; arrayVars.push_back(mv); } } } str << " return " << mtype << "::alloc(__idx, s, " << (numArray>0?"sizes":"0") << ", p);\n"; str << "}\n"; // alloc(int, size_t, int*, priobits) str << tspec << "void* " << ptype; str << "::alloc(int msgnum, size_t sz, int *sizes, int pb) {\n"; str << " CkpvAccess(_offsets)[0] = ALIGN_DEFAULT(sz);\n"; for(count = 0; count < numArray; count++) { mv = arrayVars[count]; str << " if(sizes==0)\n"; str << " CkpvAccess(_offsets)[" << count+1 << "] = CkpvAccess(_offsets)[0];\n"; str << " else\n"; str << " CkpvAccess(_offsets)[" << count+1 << "] = CkpvAccess(_offsets)[" << count << "] + "; str << "ALIGN_DEFAULT(sizeof(" << mv->type << ")*sizes[" << count << "]);\n"; } str << " return CkAllocMsg(msgnum, CkpvAccess(_offsets)[" << numArray << "], pb);\n"; str << "}\n"; str << tspec << ptype << "::" << proxyPrefix() << type << "() {\n"; str << mtype << " *newmsg = (" << mtype << " *)this;\n"; for(i=0, count=0, ml=mvlist; i<num; i++,ml=ml->next) { mv = ml->msg_var; if (mv->isArray()) { str << " newmsg->" << mv->name << " = (" << mv->type << " *) "; str << "((char *)newmsg + CkpvAccess(_offsets)[" << count << "]);\n"; count ++; } } str << "}\n"; int numCond = numConditional(); str << tspec << "void " << ptype << "::dealloc(void *p) {\n"; if (numCond > 0) { str << " " << mtype << " *msg = (" << mtype << "*) p;\n"; for(i=0, count=0, ml=mvlist; i<num; i++, ml=ml->next) { mv = ml->msg_var; if (mv->isConditional()) { if (mv->type->isPointer()) XLAT_ERROR_NOCOL("conditional variable cannot be a pointer", line); str << " CkConditional *cond_" << mv->name << " = static_cast<CkConditional*>(msg->" << mv->name << ");\n"; str << " if (cond_" << mv->name << "!=NULL) cond_" << mv->name << "->deallocate();\n"; } } } str << " CkFreeMsg(p);\n"; str << "}\n"; // pack str << tspec << "void* " << ptype << "::pack(" << mtype << " *msg) {\n"; for(i=0, ml=mvlist; i<num; i++, ml=ml->next) { mv = ml->msg_var; if (mv->isArray()) { str << " msg->" << mv->name << " = (" <<mv->type << " *) "; str << "((char *)msg->" << mv->name << " - (char *)msg);\n"; } } if (numCond > 0) { str << " int impl_off[" << numCond+1 << "];\n"; str << " impl_off[0] = UsrToEnv(msg)->getUsersize();\n"; for(i=0, count=0, ml=mvlist; i<num; i++, ml=ml->next) { mv = ml->msg_var; if (mv->isConditional()) { str << " if (msg->" << mv->name << "!=NULL) { /* conditional packing of "; mv->type->print(str); str << " " << mv->name << " */\n"; str << " PUP::sizer implP;\n"; str << " implP|*msg->" << mv->name << ";\n"; str << " impl_off[" << count+1 << "] = impl_off[" << count << "] + implP.size();\n"; str << " } else {\n"; str << " impl_off[" << count+1 << "] = impl_off[" << count << "];\n"; str << " }\n"; count ++; } } str << " " << mtype << " *newmsg = (" << mtype << "*) CkAllocMsg(__idx, impl_off[" << numCond << "], UsrToEnv(msg)->getPriobits());\n"; str << " envelope *newenv = UsrToEnv(newmsg);\n"; str << " UInt newSize = newenv->getTotalsize();\n"; str << " CmiMemcpy(newenv, UsrToEnv(msg), impl_off[0]+sizeof(envelope));\n"; str << " newenv->setTotalsize(newSize);\n"; str << " if (UsrToEnv(msg)->getPriobits() > 0) CmiMemcpy(newenv->getPrioPtr(), UsrToEnv(msg)->getPrioPtr(), newenv->getPrioBytes());\n"; for(i=0, count=0, ml=mvlist; i<num; i++, ml=ml->next) { mv = ml->msg_var; if (mv->isConditional()) { str << " if (msg->" << mv->name << "!=NULL) { /* conditional packing of "; mv->type->print(str); str << " " << mv->name << " */\n"; str << " newmsg->" << mv->name << " = ("; mv->type->print(str); str << "*)(((char*)newmsg)+impl_off[" << count << "]);\n"; str << " PUP::toMem implP((void *)newmsg->" << mv->name << ");\n"; str << " implP|*msg->" << mv->name << ";\n"; str << " newmsg->" << mv->name << " = (" << mv->type << "*) ((char *)newmsg->" << mv->name << " - (char *)newmsg);\n"; str << " }\n"; count++; } } str << " CkFreeMsg(msg);\n"; str << " msg = newmsg;\n"; } str << " return (void *) msg;\n}\n"; // unpack str << tspec << mtype << "* " << ptype << "::unpack(void* buf) {\n"; str << " " << mtype << " *msg = (" << mtype << " *) buf;\n"; for(i=0, ml=mvlist; i<num; i++, ml=ml->next) { mv = ml->msg_var; if (mv->isArray()) { str << " msg->" << mv->name << " = (" <<mv->type << " *) "; str << "((size_t)msg->" << mv->name << " + (char *)msg);\n"; } } if (numCond > 0) { for(i=0, count=0, ml=mvlist; i<num; i++, ml=ml->next) { mv = ml->msg_var; if (mv->isConditional()) { str << " if (msg->" << mv->name << "!=NULL) { /* conditional packing of "; mv->type->print(str); str << " " << mv->name << " */\n"; str << " PUP::fromMem implP((char*)msg + (size_t)msg->" << mv->name << ");\n"; str << " msg->" << mv->name << " = new " << mv->type << ";\n"; str << " implP|*msg->" << mv->name << ";\n"; str << " }\n"; count ++; } } } str << " return msg;\n}\n"; } if(!templat) { if(!external && !type->isTemplated()) { str << "int "<< ptype <<"::__idx=0;\n"; } } else { str << tspec << "int "<< ptype <<"::__idx=0;\n"; } templateGuardEnd(str); }