if (splitter.getType().equals(SIRSplitType.DUPLICATE)) {  p.print("  tmp = "+in.consumer_name()+".read_"+baseType.toString()+"();\n");
p.print("  "+baseType.toString()+" tmp;\n"); p.print("  tmp = "+in.consumer_name()+".read_"+baseType.toString()+"();\n");
    public static void generateSplitter(FlatNode node) {    		SIRSplitter splitter = (SIRSplitter)node.contents;	if (splitter.getSumOfWeights() == 0) {	    // The splitter is not doing any work	    	    return;	}	int init_counts, steady_counts;	Integer init_int = (Integer)ClusterBackend.initExecutionCounts.get(node);	if (init_int==null) {	    init_counts = 0;	} else {	    init_counts = init_int.intValue();	}	steady_counts = ((Integer)ClusterBackend.steadyExecutionCounts.get(node)).intValue();	CType baseType = Util.getBaseType(Util.getOutputType(node));	int thread_id = NodeEnumerator.getSIROperatorId(node.contents);	Vector in_v = (Vector)RegisterStreams.getNodeInStreams(node.contents);	NetStream in = (NetStream)in_v.elementAt(0);	Vector out = (Vector)RegisterStreams.getNodeOutStreams(node.contents);		TabbedPrintWriter p;	StringWriter str; 		str = new StringWriter();        p = new TabbedPrintWriter(str);			ClusterCodeGenerator gen = new ClusterCodeGenerator(splitter, new JFieldDeclaration[0]);	p.print("// init counts: "+init_counts+" steady counts: "+steady_counts+"\n"); 	p.print("\n");	//  +=============================+	//  | Preamble                    |	//  +=============================+     	Vector pre = gen.generatePreamble();	for (int i = 0; i < pre.size(); i++) {	    p.print(pre.elementAt(i).toString());	}	//  +=============================+	//  | Splitter Work               |	//  +=============================+	p.print("void __splitter_"+thread_id+"_work() {\n");	p.print("  "+baseType.toString()+" tmp;\n");	if (splitter.getType().equals(SIRSplitType.DUPLICATE)) {	    	    p.print("  tmp = "+in.consumer_name()+".read_"+baseType.toString()+"();\n");	    	    for (int i = 0; i < out.size(); i++) {		NetStream s = (NetStream)out.elementAt(i);				p.print("  "+s.producer_name()+".write_"+baseType.toString()+"(tmp);\n");	    }	} else if (splitter.getType().equals(SIRSplitType.ROUND_ROBIN)) {	    	    	    for (int i = 0; i < out.size(); i++) {		p.print("  tmp = "+in.consumer_name()+".read_"+baseType.toString()+"();\n");		NetStream s = (NetStream)out.elementAt(i);				p.print("  "+s.producer_name()+".write_"+baseType.toString()+"(tmp);\n");	    }	} else if (splitter.getType().equals(SIRSplitType.WEIGHTED_RR)) {	    /*	    for (int i = 0; i < out.size(); i++) {		int num = splitter.getWeight(i);		NetStream s = (NetStream)out.elementAt(i);						for (int ii = 0; ii < num; ii++) {		    p.print("  tmp = "+in.consumer_name()+".read_"+baseType.toString()+"();\n");		    p.print("  "+s.producer_name()+".write_"+baseType.toString()+"(tmp);\n");		}	    }	    */	    	    int sum = splitter.getSumOfWeights();	    int offs = 0;			    p.print("  "+baseType.toString()+" tmp["+sum+"];\n");	    p.print("  "+in.consumer_name()+".read_chunk(tmp, "+sum+" * sizeof("+baseType.toString()+"), "+sum+");\n");			    for (int i = 0; i < out.size(); i++) {		int num = splitter.getWeight(i);		NetStream s = (NetStream)out.elementAt(i);				p.print("  "+s.producer_name()+".write_chunk(&tmp["+offs+"], "+num+" * sizeof("+baseType.toString()+"), "+num+");\n");		offs += num;	    }	}	p.print("}\n");	p.print("\n");	//  +=============================+	//  | Splitter Work 1k            |	//  +=============================+	p.print("void __splitter_"+thread_id+"_work_1k() {\n");	if (splitter.getType().equals(SIRSplitType.DUPLICATE)) {	    	    p.print("  "+baseType.toString()+" tmp[1000 * "+steady_counts+"];\n");	    p.print("  "+in.consumer_name()+".read_chunk(tmp, 1000 * "+steady_counts+" * sizeof("+baseType.toString()+"), 1000 * "+steady_counts+");\n");			    for (int i = 0; i < out.size(); i++) {		NetStream s = (NetStream)out.elementAt(i);				p.print("  "+s.producer_name()+".write_chunk(tmp, 1000 * "+steady_counts+" * sizeof("+baseType.toString()+"), 1000 * "+steady_counts+");\n");	    }	} else {		    p.print("  for (int i = 0; i < 1000 * "+steady_counts+"; i++) __splitter_"+thread_id+"_work();\n");	}		p.print("}\n");	p.print("\n");	//  +=============================+	//  | Splitter Main               |	//  +=============================+		p.print("void __splitter_"+thread_id+"_main() {\n");	p.print("  int i, ii;\n");		p.print("  if (__steady_"+thread_id+" == 0) {\n");	p.print("    for (i = 0; i < "+init_counts+"; i++) {\n");	p.print("      check_thread_status(__state_flag_"+thread_id+",__thread_"+thread_id+");\n");	p.print("      __splitter_"+thread_id+"_work();\n");	p.print("    }\n");	p.print("  }\n");	p.print("  __steady_"+thread_id+"++;\n");	p.print("  while (__number_of_iterations_"+thread_id+" > 1000) {\n");	p.print("    check_thread_status(__state_flag_"+thread_id+",__thread_"+thread_id+");\n");	p.print("    __splitter_"+thread_id+"_work_1k();\n");	p.print("    __number_of_iterations_"+thread_id+" -= 1000;\n");	p.print("    __steady_"+thread_id+" += 1000;\n");	p.print("    if (__frequency_of_chkpts != 0 && __steady_"+thread_id+" % __frequency_of_chkpts == 0) save_state::save_to_file(__thread_"+thread_id+", __steady_"+thread_id+", __write_thread__"+thread_id+");\n");	p.print("  }\n");		p.print("  for (i = 1; i <= __number_of_iterations_"+thread_id+"; i++, __steady_"+thread_id+"++) {\n");		p.print("    for (ii = 0; ii < "+steady_counts+"; ii++) {\n");	p.print("      check_thread_status(__state_flag_"+thread_id+",__thread_"+thread_id+");\n");	p.print("      __splitter_"+thread_id+"_work();\n");	p.print("    }\n");	p.print("    if (__frequency_of_chkpts != 0 && __steady_"+thread_id+" % __frequency_of_chkpts == 0) save_state::save_to_file(__thread_"+thread_id+", __steady_"+thread_id+", __write_thread__"+thread_id+");\n");	p.print("  }\n");	p.print("}\n");	//  +=============================+	//  | Run Function                |	//  +=============================+	Vector run = gen.generateRunFunction(null, "__splitter_"+thread_id+"_main");	for (int i = 0; i < run.size(); i++) {	    p.print(run.elementAt(i).toString());	}	//  +=============================+	//  | Write Splitter to File      |	//  +=============================+		try {	    FileWriter fw = new FileWriter("thread"+thread_id+".cpp");	    fw.write(str.toString());	    fw.close();	}	catch (Exception e) {	    System.err.println("Unable to write splitter code to file thread"+thread_id+".cpp");	}		System.out.println("Code for " + node.contents.getName() +			   " written to thread"+thread_id+".cpp");    }