示例#1
0
void petabricks::MatrixDef::readFromFileCode(CodeGenerator& o, const std::string& fn, RuleFlavor rf){
  if (rf == RuleFlavor::DISTRIBUTED && numDimensions() > 0) {
    // read to tmp then copy to real matrix
    o.write(typeName(rf, false) + " tmp_" + name()+" = petabricks::MatrixIOGeneral("+fn+",\"r\").read_"+rf.str()+"<"+jalib::XToString(numDimensions())+">();");

    // allocate
    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(name()+" = "+typeName(rf)+"::allocate(tmp_"+name()+".size(), distributedcutoff, "+distributionType+", "+distributionSize+", "+migrationType+");");

    // copy
    o.beginIf(name()+".isRegionDataRaw()");
    o.write(name()+" = tmp_"+name()+";");
    o.elseIf();
    o.write(name()+".fromScratchRegion(tmp_"+name()+");");
    o.endIf();

    // o.write("petabricks::MatrixIOGeneral().write("+name()+");");

  } else {
    o.varDecl(name()+" = petabricks::MatrixIOGeneral("+fn+",\"r\").read_"+rf.str()+"<"+jalib::XToString(numDimensions())+">()");
  }
}
示例#2
0
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();
}