public static ArrayList<ProgramBlock> rcreateDeepCopyProgramBlocks(ArrayList<ProgramBlock> childBlocks,long pid,int IDPrefix,HashSet<String> fnStack,HashSet<String> fnCreated,boolean plain,boolean forceDeepCopy) throws DMLRuntimeException {
  ArrayList<ProgramBlock> tmp=new ArrayList<ProgramBlock>();
  for (  ProgramBlock pb : childBlocks) {
    Program prog=pb.getProgram();
    ProgramBlock tmpPB=null;
    if (pb instanceof WhileProgramBlock) {
      tmpPB=createDeepCopyWhileProgramBlock((WhileProgramBlock)pb,pid,IDPrefix,prog,fnStack,fnCreated,plain,forceDeepCopy);
    }
 else     if (pb instanceof ForProgramBlock && !(pb instanceof ParForProgramBlock)) {
      tmpPB=createDeepCopyForProgramBlock((ForProgramBlock)pb,pid,IDPrefix,prog,fnStack,fnCreated,plain,forceDeepCopy);
    }
 else     if (pb instanceof ParForProgramBlock) {
      ParForProgramBlock pfpb=(ParForProgramBlock)pb;
      if (ParForProgramBlock.ALLOW_NESTED_PARALLELISM)       tmpPB=createDeepCopyParForProgramBlock(pfpb,pid,IDPrefix,prog,fnStack,fnCreated,plain,forceDeepCopy);
 else       tmpPB=createDeepCopyForProgramBlock((ForProgramBlock)pb,pid,IDPrefix,prog,fnStack,fnCreated,plain,forceDeepCopy);
    }
 else     if (pb instanceof IfProgramBlock) {
      tmpPB=createDeepCopyIfProgramBlock((IfProgramBlock)pb,pid,IDPrefix,prog,fnStack,fnCreated,plain,forceDeepCopy);
    }
 else {
      tmpPB=new ProgramBlock(prog);
      tmpPB.setStatementBlock(createStatementBlockCopy(pb.getStatementBlock(),pid,plain,forceDeepCopy));
      tmpPB.setThreadID(pid);
    }
    tmpPB.setInstructions(createDeepCopyInstructionSet(pb.getInstructions(),pid,IDPrefix,prog,fnStack,fnCreated,plain,true));
    tmp.add(tmpPB);
  }
  return tmp;
}

public static ArrayList < ProgramBlock > rcreateDeepCopyProgramBlocks ( ArrayList < ProgramBlock > childBlocks , long pid , int IDPrefix , HashSet < String > fnStack , HashSet < String > fnCreated , boolean plain , boolean forceDeepCopy ) throws DMLRuntimeException { ArrayList < ProgramBlock > tmp = new ArrayList < ProgramBlock > ( ) ; for ( ProgramBlock pb : childBlocks ) { Program prog = pb . getProgram ( ) ; ProgramBlock tmpPB = null ; if ( pb instanceof WhileProgramBlock ) { tmpPB = createDeepCopyWhileProgramBlock ( ( WhileProgramBlock ) pb , pid , IDPrefix , prog , fnStack , fnCreated , plain , forceDeepCopy ) ; } else if ( pb instanceof ForProgramBlock && ! ( pb instanceof ParForProgramBlock ) ) { tmpPB = createDeepCopyForProgramBlock ( ( ForProgramBlock ) pb , pid , IDPrefix , prog , fnStack , fnCreated , plain , forceDeepCopy ) ; } else if ( pb instanceof ParForProgramBlock ) { ParForProgramBlock pfpb = ( ParForProgramBlock ) pb ; if ( ParForProgramBlock . ALLOW_NESTED_PARALLELISM ) tmpPB = createDeepCopyParForProgramBlock ( pfpb , pid , IDPrefix , prog , fnStack , fnCreated , plain , forceDeepCopy ) ; else tmpPB = createDeepCopyForProgramBlock ( ( ForProgramBlock ) pb , pid , IDPrefix , prog , fnStack , fnCreated , plain , forceDeepCopy ) ; } else if ( pb instanceof IfProgramBlock ) { tmpPB = createDeepCopyIfProgramBlock ( ( IfProgramBlock ) pb , pid , IDPrefix , prog , fnStack , fnCreated , plain , forceDeepCopy ) ; } else { tmpPB = new ProgramBlock ( prog ) ; tmpPB . setStatementBlock ( createStatementBlockCopy ( pb . getStatementBlock ( ) , pid , plain , forceDeepCopy ) ) ; tmpPB . setThreadID ( pid ) ; } tmpPB . setInstructions ( createDeepCopyInstructionSet ( pb . getInstructions ( ) , pid , IDPrefix , prog , fnStack , fnCreated , plain , true ) ) ; tmp . add ( tmpPB ) ; } return tmp ; }
this recursively creates a deep copy of program blocks and transparently replaces filenames according to the specified parallel worker in order to avoid conflicts between parworkers . this happens recursively in order to support arbitrary control - flow constructs within a parfor .
