void petabricks::MatrixDef::allocateTemporary(CodeGenerator& o, RuleFlavor rf, bool setOnly, bool reallocAllowed){ if(!setOnly) o.addMember(typeName(rf), name(), ""); if(reallocAllowed) o.beginIf("!"+name()+".isSize("+_size.toString()+")"); if (rf == RuleFlavor::DISTRIBUTED && numDimensions() > 0) { std::string distributionType = o.className() + "_" + name() + "_distribution_type"; std::string distributionSize = o.className() + "_" + name() + "_distribution_size"; std::string migrationType = o.className() + "_" + name() + "_migration_type"; o.createTunable(true, "system.data.distribution.type", distributionType, 0, 0, 5); o.createTunable(true, "system.data.distribution.size", distributionSize, jalib::maxval<int>(), 2, jalib::maxval<int>()); o.createTunable(true, "system.data.migration.type", migrationType, 0, 0, 1); o.write("{"); o.incIndent(); o.write("IndexT size[] = {"+_size.toString()+"};"); o.write(name()+" = "+typeName(rf)+"::allocate(size, distributedcutoff, "+distributionType+", "+distributionSize+", "+migrationType+");"); o.decIndent(); o.write("}"); } else { o.write(name()+" = "+allocateStr(rf)+";"); } if(reallocAllowed) o.endIf(); }
void petabricks::MatrixDef::extractDefines(FreeVars& defined, CodeGenerator& o){ int d=0; for(FormulaList::const_iterator i=_size.begin(); i!=_size.end(); ++i,++d){ FreeVarsPtr fv = (*i)->getFreeVariables(); if(fv->size()==1){ std::string var = *fv->begin(); FormulaPtr tmp = FormulaVariable::mktmp(); if(!defined.contains(var)){ defined.insert(var); FormulaList l; l.push_back(new FormulaEQ(tmp, *i)); l = *MaximaWrapper::instance().solve(l, var); JASSERT(l.size()==1)(*i)(var).Text("Failed to solve"); o.addMember("IndexT", var, ""); o.write(var + " = " + (*l.begin())->rhs()->replace(tmp, new FormulaVariable(_name+".size("+jalib::XToString(d)+")"))->toString() + ";"); } } } }
void petabricks::MatrixDef::varDeclCode(CodeGenerator& o, RuleFlavor rf, bool isConst){ o.addMember(typeName(rf, isConst), name(), ""); }