p.print("  __head__" + selfID + "=" + extra + ";\n");
p.print("  __head__" + selfID + "=" + init_pop_count + ";\n");
    public void visitFilter(SIRFilter self, SIRFilterIter iter) {        // create code for this filter to include in         // ClusterCodegenerator.generateRunFunction        cleanupCode = new Vector();                filter = self;                selfID = NodeEnumerator.getSIROperatorId(self); // needed by the class        method_names = new HashSet();        JMethodDeclaration[] meth = self.getMethods();        for (int i = 0; i < meth.length; i++) {            method_names.add(meth[i].getName());        }        HashSet sendsCreditsTo = LatencyConstraints                .getOutgoingConstraints(self);        boolean restrictedExecution = LatencyConstraints.isRestricted(self);        boolean sendsCredits = (sendsCreditsTo.size() > 0);        SIRPortal outgoing[] = SIRPortal.getPortalsWithSender(self);        SIRPortal incoming[] = SIRPortal.getPortalsWithReceiver(self);        Vector sends_to = new Vector();        Vector receives_from = new Vector();        FlatNode node = NodeEnumerator.getFlatNode(selfID);        System.out.println("flat node: " + node);        Integer init_int = (Integer) ClusterBackend.initExecutionCounts                .get(node);        int init_counts;        if (init_int == null) {            init_counts = 0;        } else {            init_counts = init_int.intValue();        }        int steady_counts = ((Integer) ClusterBackend.steadyExecutionCounts                .get(node)).intValue();        for (int t = 0; t < outgoing.length; t++) {            SIRStream[] receivers = outgoing[t].getReceivers();            for (int i = 0; i < receivers.length; i++) {                sends_to.add(receivers[i]);            }        }        for (int t = 0; t < incoming.length; t++) {            SIRPortalSender[] senders = incoming[t].getSenders();            for (int i = 0; i < senders.length; i++) {                receives_from.add(senders[i].getStream());            }        }        int pop_n, peek_n, push_n;        pop_n = self.getPopInt();        peek_n = self.getPeekInt();        push_n = self.getPushInt();        p.print("// peek: " + peek_n + " pop: " + pop_n + " push " + push_n                + "\n");        p.print("// init counts: " + init_counts + " steady counts: "                + steady_counts + "\n");        p.newLine();        int data = DataEstimate.filterGlobalsSize(self);        CodeEstimate est = CodeEstimate.estimate(self);        // int code = CodeEstimate.estimateCode(self);        // int locals = CodeEstimate.estimateLocals(self);        int code = est.getCodeSize();        int locals = est.getLocalsSize();        System.out.println("[globals: " + data + " locals: " + locals                + " code: " + code + "]");        ClusterCodeGenerator gen = new ClusterCodeGenerator(self, self                .getFields());        Vector pre = gen.generatePreamble();        for (int i = 0; i < pre.size(); i++) {            p.print(pre.elementAt(i).toString());        }        // +=============================+        // | Method Declarations |        // +=============================+        JMethodDeclaration work = self.getWork();        // visit methods of filter, print the declaration first        declOnly = true;        JMethodDeclaration[] methods = self.getMethods();        for (int i = 0; i < methods.length; i++) {            if (!methods[i].equals(work))                methods[i].accept(this);        }        p.newLine();        p.print("inline void check_status__" + selfID + "();\n");        p.print("void check_messages__" + selfID + "();\n");        p.print("void handle_message__" + selfID + "(netsocket *sock);\n");        p.print("void send_credits__" + selfID + "();\n");        p.newLine();        // +=============================+        // | Push / Pop |        // +=============================+        CType input_type = self.getInputType();        CType output_type = self.getOutputType();        NetStream in = RegisterStreams.getFilterInStream(self);        NetStream out = RegisterStreams.getFilterOutStream(self);        int out_pop_buffer_size = 10240;        int out_pop_num_iters = 0;        if (push_n != 0) {            out_pop_num_iters = out_pop_buffer_size / push_n;        }        if (out != null) {            // p.print(ClusterUtils.CTypeToString(output_type)            // +" "+out.pop_buffer()+"["+push_n+"];\n");            // p.print("int "+out.pop_index()+" = "+push_n+";\n");            p.print(ClusterUtils.CTypeToString(output_type) + " "                    + out.pop_buffer() + "[" + out_pop_buffer_size + "];\n");            p.print("int " + out.pop_index() + " = "                    + (out_pop_num_iters * push_n) + ";\n");            p.newLine();        }        if (in != null) {            FlatNode source_node = NodeEnumerator.getFlatNode(in.getSource());            FlatNode my_node = NodeEnumerator.getFlatNode(selfID);            // String pop_expr = null;            FlatNode source_master = ClusterFusion.getLocalMaster(source_node);            boolean source_fused = (source_master != null && source_master                    .equals(my_node));            // if {            // pop_expr = in.pop_name();            // } else {            // pop_expr = in.consumer_name()+".pop";            // }            int peek_buf_size = 1;            while (peek_buf_size < peek_n) {                peek_buf_size *= 2;            }            p.print(ClusterUtils.CTypeToString(input_type) + " __pop_buf__"                    + selfID + "[" + peek_buf_size + "];\n");            p.print("int __head__" + selfID + ";\n");            p.print("int __tail__" + selfID + ";\n");            p.newLine();            int extra = peek_n - pop_n;            // assert (extra >= 0);            if (extra < 0)                extra = 0;            p.print("inline void __init_pop_buf__" + selfID + "() {\n");            for (int i = 0; i < extra; i++) {                p.print("  __pop_buf__" + selfID + "[" + i + "]=");                if (source_fused) {                    p.print(in.pop_name() + "();\n");                } else {                    p.print(in.consumer_name() + ".pop();\n");                }            }            p.print("  __tail__" + selfID + "=0;\n");            p.print("  __head__" + selfID + "=" + extra + ";\n");            /*             *              * if (source_fused) {             *              * for (int y = 0; y < extra; y++) { int index = y + pop_n;             *              * p.print(" __pop_buf__"+selfID+"["+index+"] =             * "+in.pop_name()+"();\n"); } } else {             *              * if (pop_n < 8) {             *              * for (int i = 0; i < extra; i++) { p.print("             * __pop_buf__"+selfID+"["+(pop_n+i)+"] =             * "+in.consumer_name()+".pop();\n"); }             *  } else {             *              *              * p.print("             * "+in.consumer_name()+".pop_items(&__pop_buf__"+selfID+"["+pop_n+"],             * "+extra+");\n"); }             *  }             */            p.print("}\n");            p.newLine();            p.print("void save_peek_buffer__" + selfID                    + "(object_write_buffer *buf) {\n");            p.print("  int i = 0, offs = __tail__" + selfID + ";\n");            p.print("  while (offs != __head__" + selfID + ") {\n");            p.print("    buf->write(&__pop_buf__" + selfID + "[offs], sizeof("                    + ClusterUtils.CTypeToString(input_type)                    + "));\n    offs++;\n    offs&=" + (peek_buf_size - 1)                    + ";\n    i++;\n");            p.print("  }\n");            // p.print(" fprintf(stderr,\"buf size: %d\\n\", i);\n");            p.print("  assert(i == " + extra + ");\n");            p.print("}\n");            p.newLine();            p.print("void load_peek_buffer__" + selfID                    + "(object_write_buffer *buf) {\n");            p.print("  for (int i = 0; i < " + extra + "; i++) {\n");            p.print("     buf->read(&__pop_buf__" + selfID + "[i] , sizeof("                    + ClusterUtils.CTypeToString(input_type) + "));\n");            p.print("  }\n");            p.print("  __tail__" + selfID + "=0;\n");            p.print("  __head__" + selfID + "=" + extra + ";\n");            p.print("}\n");            p.newLine();            p.print("inline void __update_pop_buf__" + selfID + "() {\n");            if (peek_n <= pop_n) {                // no peek beyond pop                for (int i = 0; i < pop_n; i++) {                    p.print("  __pop_buf__" + selfID + "[" + i + "]=");                    if (source_fused) {                        p.print(in.pop_name() + "();");                    } else {                        p.print(in.consumer_name() + ".pop();");                    }                    p.newLine();                }                p.print("  __tail__" + selfID + " = 0;\n");                p.print("  __head__" + selfID + " = " + pop_n + ";\n");            } else {                // peek beyond pop => circular buffer                for (int i = 0; i < pop_n; i++) {                    p.print("  __pop_buf__" + selfID + "[__head__" + selfID                            + "]=");                    if (source_fused) {                        p.print(in.pop_name() + "();");                    } else {                        p.print(in.consumer_name() + ".pop();");                    }                    p.print("__head__" + selfID + "++;");                    p.print("__head__" + selfID + "&=" + (peek_buf_size - 1)                            + ";\n");                }            }            /*             * p.print(" __pop_index__"+selfID+" = 0;\n");             *              * int extra = peek_n - pop_n; for (int y = 0; y < extra; y++) { int             * index = y + pop_n; p.print(" __pop_buf__"+selfID+"["+y+"] =             * __pop_buf__"+selfID+"["+index+"];\n"); }             *              * if (source_fused) {             *              * for (int y = 0; y < pop_n; y++) { int index = y + extra;             * p.print(" __pop_buf__"+selfID+"["+index+"] =             * "+in.pop_name()+"();\n"); } } else {             *              * if (pop_n < 8) {             *              * for (int i = 0; i < pop_n; i++) { p.print("             * __pop_buf__"+selfID+"["+(extra+i)+"] =             * "+in.consumer_name()+".pop();\n"); }             *  } else {             *              * p.print("             * "+in.consumer_name()+".pop_items(&__pop_buf__"+selfID+"["+extra+"],             * "+pop_n+");\n"); }             *  }             */            p.print("}\n");            p.newLine();            int s = in.getSource();            int d = in.getDest();            p.print("#ifdef __FUSED_" + s + "_" + d + "\n");            // the filter is fused with its source            p.newLine();            p.print("  extern " + ClusterUtils.CTypeToString(input_type)                    + " BUFFER_" + s + "_" + d + "[];\n");            p.print("  extern volatile int HEAD_" + s + "_" + d + ";\n");            p.print("  extern volatile int TAIL_" + s + "_" + d + ";\n");            // p.print(" extern int HEAD_"+s+"_"+d+";\n");            // p.print(" extern int TAIL_"+s+"_"+d+";\n");            p.newLine();            // pop from fusion buffer            p.print("  inline " + ClusterUtils.CTypeToString(input_type)                    + " __pop__" + selfID + "() {\n");            p.print("    " + ClusterUtils.CTypeToString(input_type)                    + " res=BUFFER_" + s + "_" + d + "[TAIL_" + s + "_" + d                    + "];\n");            p.print("    TAIL_" + s + "_" + d + "++;\n");            p.print("    #ifndef __NOMOD_" + s + "_" + d + "\n");            p.print("    TAIL_" + s + "_" + d + "&=__BUF_SIZE_MASK_" + s + "_"                    + d + ";\n");            p.print("    #endif\n");            p.print("    return res;\n");            p.print("  }\n");            p.newLine();            // peek from fusion buffer            p.print("  inline " + ClusterUtils.CTypeToString(input_type) + " "                    + ClusterUtils.peekName(selfID) + "(int offs) {\n");            p.print("    #ifdef __NOMOD_" + s + "_" + d + "\n");            p.print("    return BUFFER_" + s + "_" + d + "[TAIL_" + s + "_" + d                    + "+offs];\n");            p.print("    #else\n");            p.print("    return BUFFER_" + s + "_" + d + "[(TAIL_" + s + "_"                    + d + "+offs)&__BUF_SIZE_MASK_" + s + "_" + d + "];\n");            p.print("    #endif\n");            p.print("  }\n");            p.newLine();            // the source is not fused            p.print("#else //!__FUSED_" + s + "_" + d + "\n");            p.newLine();            p.print("  inline " + ClusterUtils.CTypeToString(input_type)                    + " __pop__" + selfID + "() {\n");            if (peek_n <= pop_n) {                p.print("    return __pop_buf__" + selfID + "[__tail__"                        + selfID + "++];\n");            } else {                p.print("    " + ClusterUtils.CTypeToString(input_type)                        + " res=__pop_buf__" + selfID + "[__tail__" + selfID                        + "];");                p.print("__tail__" + selfID + "++;");                p.print("__tail__" + selfID + "&=" + (peek_buf_size - 1)                        + ";\n");                p.print("    return res;\n");            }            // p.print(" return            // __pop_buf__"+selfID+"[__pop_index__"+selfID+"++];\n");            p.print("  }\n");            p.newLine();            p.print("  inline " + ClusterUtils.CTypeToString(input_type) + " "                    + ClusterUtils.peekName(selfID) + "(int offs) {\n");            if (peek_n <= pop_n) {                p.print("    return __pop_buf__" + selfID + "[(__tail__"                        + selfID + "+offs)];\n");            } else {                p.print("    return __pop_buf__" + selfID + "[(__tail__"                        + selfID + "+offs)&" + (peek_buf_size - 1) + "];\n");            }            // p.print(" return __pop_buf__"+selfID            // +"[__pop_index__"+selfID+" + offs];\n");            p.print("  }\n");            p.newLine();            p.print("#endif\n");            p.newLine();        } else {            p.print("inline " + ClusterUtils.CTypeToString(input_type)                    + " __init_pop_buf__" + selfID + "() {}\n");            p.print("inline " + ClusterUtils.CTypeToString(input_type)                    + " __update_pop_buf__" + selfID + "() {}\n");            p.print("void save_peek_buffer__" + selfID                    + "(object_write_buffer *buf) {}\n");            p.print("void load_peek_buffer__" + selfID                    + "(object_write_buffer *buf) {}\n");            p.newLine();        }        if (out != null) {            FlatNode dst_node = NodeEnumerator.getFlatNode(out.getDest());            FlatNode my_node = NodeEnumerator.getFlatNode(selfID);            // String push_expr = null;            FlatNode dst_master = ClusterFusion.getLocalMaster(dst_node);            FlatNode my_master = ClusterFusion.getLocalMaster(my_node);            int s = out.getSource();            int d = out.getDest();            // check if the destination node is fused            p.print("#ifdef __FUSED_" + s + "_" + d + "\n");            p.newLine();            p.print("  extern " + ClusterUtils.CTypeToString(output_type)                    + " BUFFER_" + s + "_" + d + "[];\n");            p.print("  extern int HEAD_" + s + "_" + d + ";\n");            p.print("  extern int TAIL_" + s + "_" + d + ";\n");            p.newLine();            p.print("  inline void " + ClusterUtils.pushName(selfID) + "("                    + ClusterUtils.CTypeToString(output_type) + " data) {\n");            p.print("    BUFFER_" + s + "_" + d + "[HEAD_" + s + "_" + d                    + "]=data;\n");            p.print("    HEAD_" + s + "_" + d + "++;\n");            p.print("    #ifndef __NOMOD_" + s + "_" + d + "\n");            p.print("    HEAD_" + s + "_" + d + "&=__BUF_SIZE_MASK_" + s + "_"                    + d + ";\n");            p.print("    #endif\n");            p.print("  }\n");            p.newLine();            // if not fused use the producer's push function            p.print("#else //!__FUSED_" + s + "_" + d + "\n");            p.newLine();            p.print("  inline void " + ClusterUtils.pushName(selfID) + "("                    + ClusterUtils.CTypeToString(output_type) + " data) {\n");            if (dst_master != null && dst_master.equals(my_node)) {                p.print("  " + out.push_name() + "(data);\n");            } else if (my_master != null && my_master.equals(dst_node)) {                p.print("  " + out.pop_buffer() + "[" + out.pop_index()                        + "++] = data;\n");            } else {                p.print("  " + out.producer_name() + ".push(data);\n");            }            p.print("  }\n");            p.newLine();            p.print("#endif");            p.newLine();        }        if (in != null) {            p.print("void " + in.push_name() + "("                    + ClusterUtils.CTypeToString(input_type) + " data) {}\n");            p.newLine();        }        p.newLine();        if (out != null) {            // p.print("void            // "+ClusterExecutionCode.rawMain+"__"+selfID+"();\n");            p.print("void " + ClusterUtils.getWorkName(self, selfID)                    + "(int);\n\n");            p.print(ClusterUtils.CTypeToString(output_type) + " "                    + out.pop_name() + "() {\n");            p.print("  int _tmp;\n");            /*             * p.print(" if ("+out.pop_index()+" == "+push_n+") {\n"); p.print("             * int tmp = __number_of_iterations_"+selfID+";\n"); p.print("             * __number_of_iterations_"+selfID+" = 1;\n"); p.print("             * "+out.pop_index()+" = 0;\n"); p.print("             * "+ClusterExecutionCode.rawMain+"__"+selfID+"();\n"); p.print("             * __number_of_iterations_"+selfID+" = tmp - 1;\n"); p.print("             * "+out.pop_index()+" = 0;\n");             */            p.print("  if (" + out.pop_index() + " == "                    + (out_pop_num_iters * push_n) + ") {\n");            p.print("    " + out.pop_index() + " = 0;\n");            p.print("    for (_tmp = 0; _tmp < " + out_pop_num_iters                    + "; _tmp++) {\n");            p.print("      //check_status__" + selfID + "();\n");            p.print("      check_messages__" + selfID + "();\n");            p.print("      __update_pop_buf__" + selfID + "();\n");            p.print("      " + ClusterUtils.getWorkName(self, selfID)                    + "(1);\n");            p.print("      //send_credits__" + selfID + "();\n");            p.print("    }\n");            p.print("    " + out.pop_index() + " = 0;\n");            /*             * p.print(" int tmp = __number_of_iterations_"+selfID+";\n");             * p.print(" __number_of_iterations_"+selfID+" =             * "+out_pop_num_iters+";\n"); p.print(" "+out.pop_index()+" =             * 0;\n"); p.print("             * "+ClusterExecutionCode.rawMain+"__"+selfID+"();\n"); p.print("             * __number_of_iterations_"+selfID+" = tmp -             * "+out_pop_num_iters+";\n"); p.print(" "+out.pop_index()+" =             * 0;\n");             */            p.print("  }\n");            p.print("  return " + out.pop_buffer() + "[" + out.pop_index()                    + "++];\n");            p.print("}\n");            p.newLine();        }        // +=============================+        // | Method Bodies |        // +=============================+        declOnly = false;        for (int i = 0; i < methods.length; i++) {            if (!methods[i].equals(work))                methods[i].accept(this);            // methods[i].accept(this);        }        // +=============================+        // | Work Function (int ____n) |        // +=============================+        JBlock block = new JBlock(null, new JStatement[0], null);        JVariableDefinition counter = new JVariableDefinition(null, 0,                CStdType.Integer, "____n", new JIntLiteral(0));        /*         *          * JVariableDefinition tmp = new JVariableDefinition(null, 0,         * CStdType.Integer, "____tmp", new JLocalVariableExpression(null,         * counter)); // int ____tmp = ____n;         *          */        JVariableDefinition iter_counter = new JVariableDefinition(null, 0,                CStdType.Integer, "__counter_" + selfID, null);        JStatement init = new JEmptyStatement(null, null);        // VariableDeclarationStatement(null, tmp, null);        JExpression decrExpr = new JPostfixExpression(null,                Constants.OPE_POSTDEC, new JLocalVariableExpression(null,                        counter));        JStatement decr = new JExpressionStatement(null, decrExpr, null);        JExpression cond = new JRelationalExpression(null, Constants.OPE_LT,                new JIntLiteral(0), new JLocalVariableExpression(null, counter));        if (self instanceof SIRPredefinedFilter) {            BuiltinsCodeGen.predefinedFilterWork((SIRPredefinedFilter) self,                    selfID, p);        } else {            block.addStatement(new JForStatement(null, init, cond, decr, work                    .getBody(), null));            // __counter_X = __counter_X + ____n;            /*             * block.addStatement(new JExpressionStatement( null, new             * JAssignmentExpression (null, new JLocalVariableExpression (null,             * iter_counter), new JAddExpression(null, new             * JLocalVariableExpression (null, iter_counter), new             * JLocalVariableExpression (null, counter))), null));             *              *              */            JFormalParameter param = new JFormalParameter(null, 0,                    CStdType.Integer, "____n", true);            JFormalParameter params[] = new JFormalParameter[1];            params[0] = param;            JMethodDeclaration work_n = new JMethodDeclaration(null,                    at.dms.kjc.Constants.ACC_PUBLIC, CStdType.Void, work                            .getName(), params, CClassType.EMPTY, block, null,                    null);            work_n.accept(this);        }        // +=============================+        // | Check Messages |        // +=============================+        p.print("\nvoid check_messages__" + selfID + "() {\n");        p.print("  message *msg, *last = NULL;\n");        if (restrictedExecution) {            p.print("  while (__credit_" + selfID + " <= __counter_" + selfID                    + ") {\n");        }        {            Iterator i = receives_from.iterator();            while (i.hasNext()) {                int src = NodeEnumerator.getSIROperatorId((SIRStream) i.next());                p.print("  if (__msg_sock_" + src + "_" + selfID                        + "in->data_available()) {\n    handle_message__"                        + selfID + "(__msg_sock_" + src + "_" + selfID                        + "in);\n  } // if\n");            }        }        if (restrictedExecution) {            p.print("  } // while \n");        }        p.print("  for (msg = __msg_stack_" + selfID                + "; msg != NULL; msg = msg->next) {\n");        p.print("    if (msg->execute_at <= __counter_" + selfID + ") {\n");        SIRPortal[] portals = SIRPortal.getPortalsWithReceiver(self);        /* there should be only one portal or none */        if (portals.length == 1) {            CClass pclass = portals[0].getPortalType().getCClass();            CMethod pmethods[] = pclass.getMethods();            for (int i = 0; i < pmethods.length; i++) {                CMethod portal_method = pmethods[i];                CType portal_method_params[] = portal_method.getParameters();                String method_name = portal_method.getIdent();                int length = method_name.length();                if (!method_name.startsWith("<") && !method_name.endsWith(">")) {                    p.print("      if (msg->method_id == " + i + ") {\n");                    for (int t = 0; t < methods.length; t++) {                        String thread_method_name = methods[t].getName();                        if (thread_method_name.startsWith(method_name)                                && thread_method_name.charAt(length) == '_'                                && thread_method_name.charAt(length + 1) == '_') {                            int param_count = methods[t].getParameters().length;                            for (int a = 0; a < param_count; a++) {                                if (portal_method_params[a].toString().equals(                                        "int")) {                                    p.print("        int p" + a                                            + " = msg->get_int_param();\n");                                }                                if (portal_method_params[a].toString().equals(                                        "float")) {                                    p.print("        float p" + a                                            + " = msg->get_float_param();\n");                                }                            }                            p.print("        " + thread_method_name + "__"                                    + selfID + "(");                            for (int a = 0; a < param_count; a++) {                                if (a > 0)                                    p.print(", ");                                p.print("p" + a);                            }                            p.print(");\n");                        }                    }                    p.print("      }\n");                }            }            p.print("      if (last != NULL) { \n");            p.print("        last->next = msg->next;\n");            p.print("      } else {\n");            p.print("        __msg_stack_" + selfID + " = msg->next;\n");            p.print("      }\n");            p.print("      delete msg;\n");        }        p.print("    } else { last = msg; }\n");        p.print("  } // for \n");        p.print("}\n");        // +=============================+        // | Handle Message |        // +=============================+        p.print("\nvoid handle_message__" + selfID + "(netsocket *sock) {\n");        p.print("  int size = sock->read_int();\n");        if (restrictedExecution) {            p.print("  i (size == -1) { // a credit message received\n");            p.print("    __credit_" + selfID + " = sock->read_int();\n");            p.print("    return;\n");            p.print("  };\n");        }        p.print("  int index = sock->read_int();\n");        p.print("  int iteration = sock->read_int();\n");        p                .print("  fprintf(stderr,\"Message receieved! thread: "                        + selfID                        + ", method_index: %d excute at iteration: %d\\n\", index, iteration);\n");        p.print("  if (iteration > 0) {\n");        p.print("    message *msg = new message(size, index, iteration);\n");        p.print("    msg->read_params(sock);\n");        p.print("    __msg_stack_" + selfID                + " = msg->push_on_stack(__msg_stack_" + selfID + ");\n");        p.print("    return;\n");        p.print("  }\n");        // SIRPortal[] portals = SIRPortal.getPortalsWithReceiver(self);        /* there should be only one portal or none */        if (portals.length == 1) {            CClass pclass = portals[0].getPortalType().getCClass();            CMethod pmethods[] = pclass.getMethods();            for (int i = 0; i < pmethods.length; i++) {                CMethod portal_method = pmethods[i];                CType portal_method_params[] = portal_method.getParameters();                String method_name = portal_method.getIdent();                int length = method_name.length();                if (!method_name.startsWith("<") && !method_name.endsWith(">")) {                    p.print("  if (index == " + i + ") {\n");                    for (int t = 0; t < methods.length; t++) {                        String thread_method_name = methods[t].getName();                        if (thread_method_name.startsWith(method_name)                                && thread_method_name.charAt(length) == '_'                                && thread_method_name.charAt(length + 1) == '_') {                            int param_count = methods[t].getParameters().length;                            for (int a = 0; a < param_count; a++) {                                if (portal_method_params[a].toString().equals(                                        "int")) {                                    p.print("    int p" + a                                            + " = sock->read_int();\n");                                }                                if (portal_method_params[a].toString().equals(                                        "float")) {                                    p.print("    float p" + a                                            + " = sock->read_float();\n");                                }                            }                            p.print("    " + thread_method_name + "__" + selfID                                    + "(");                            for (int a = 0; a < param_count; a++) {                                if (a > 0)                                    p.print(", ");                                p.print("p" + a);                            }                            p.print(");\n");                        }                    }                    p.print("  }\n");                }            }        }        p.print("}\n");        // +=============================+        // | Send Credits |        // +=============================+        Iterator constrIter;        constrIter = sendsCreditsTo.iterator();        while (constrIter.hasNext()) {            LatencyConstraint constraint = (LatencyConstraint) constrIter                    .next();            int receiver = NodeEnumerator.getSIROperatorId(constraint                    .getReceiver());            int sourcePhase = constraint.getSourceSteadyExec();            p.print("int __init_" + selfID + "_" + receiver + " = "                    + constraint.getSourceInit() + ";\n");            p.print("int __source_phase_" + selfID + "_" + receiver + " = "                    + sourcePhase + ";\n");            p.print("int __dest_phase_" + selfID + "_" + receiver + " = "                    + constraint.getDestSteadyExec() + ";\n");            p.print("int __current_" + selfID + "_" + receiver + " = 0;\n");            p.print("int __dest_offset_" + selfID + "_" + receiver + " = 0;\n");            p.print("int __dependency_" + selfID + "_" + receiver + "[] = {");            int y;            for (y = 0; y < sourcePhase - 1; y++) {                p.print(constraint.getDependencyData(y) + ",");            }            p.print(constraint.getDependencyData(y) + "};\n");            p.newLine();        }        p.print("\ninline void send_credits__" + selfID + "() {\n");        p.print("  int tmp;\n");        // HashSet sendsCreditsTo =        // LatencyConstraints.getOutgoingConstraints(self);        // boolean restrictedExecution = LatencyConstraints.isRestricted(self);        // boolean sendsCredits;        constrIter = sendsCreditsTo.iterator();        while (constrIter.hasNext()) {            LatencyConstraint constraint = (LatencyConstraint) constrIter                    .next();            int receiver = NodeEnumerator.getSIROperatorId(constraint                    .getReceiver());            if (LatencyConstraints.isMessageDirectionDownstream(self,                    constraint.getReceiver())) {                // message and credit is sent downstream                p.print("  if (__counter_" + selfID + " > __init_" + selfID                        + "_" + receiver + ") {\n");                p.print("    tmp = __dependency_" + selfID + "_" + receiver                        + "[__current_" + selfID + "_" + receiver + "];\n");                p.print("    if (tmp > 0) {\n");                p.print("      __msg_sock_" + selfID + "_" + receiver                        + "out->write_int(-1);\n");                p.print("      __msg_sock_" + selfID + "_" + receiver                        + "out->write_int(tmp + __dest_offset_" + selfID + "_"                        + receiver + ");\n");                p.print("    }\n");                p.print("    __current_" + selfID + "_" + receiver                        + " = (__current_" + selfID + "_" + receiver                        + " + 1) % __source_phase_" + selfID + "_" + receiver                        + ";\n");                p                        .print("    if (__current_" + selfID + "_" + receiver                                + " == 0) __dest_offset_" + selfID + "_"                                + receiver + " += __dest_phase_" + selfID + "_"                                + receiver + ";\n");                p.print("  }\n");            } else {                // message and credit is sent upstream                p.print("  if (__counter_" + selfID + " == 0) {\n");                p.print("    __msg_sock_" + selfID + "_" + receiver                        + "out->write_int(-1);\n");                p.print("    __msg_sock_" + selfID + "_" + receiver                        + "out->write_int(__init_" + selfID + "_" + receiver                        + ");\n");                p.print("  } else {\n");                p.print("    tmp = __dependency_" + selfID + "_" + receiver                        + "[__current_" + selfID + "_" + receiver + "];\n");                p.print("    if (tmp > 0) {\n");                p.print("      __msg_sock_" + selfID + "_" + receiver                        + "out->write_int(-1);\n");                p.print("      __msg_sock_" + selfID + "_" + receiver                        + "out->write_int(tmp + __dest_offset_" + selfID + "_"                        + receiver + ");\n");                p.print("    }\n");                p.print("    __current_" + selfID + "_" + receiver                        + " = (__current_" + selfID + "_" + receiver                        + " + 1) % __source_phase_" + selfID + "_" + receiver                        + ";\n");                p                        .print("    if (__current_" + selfID + "_" + receiver                                + " == 0) __dest_offset_" + selfID + "_"                                + receiver + " += __dest_phase_" + selfID + "_"                                + receiver + ";\n");                p.print("  }\n");            }        }        p.print("}\n");        // +=============================+        // | Cluster Main |        // +=============================+        Vector run =             gen.generateRunFunction(filter.getInit().getName() + "__"                                    + selfID,                                     ClusterUtils.getWorkName(filter, selfID),                                    cleanupCode);        for (int i = 0; i < run.size(); i++) {            p.print(run.elementAt(i).toString());        }        createFile(selfID);    }