00001 #include "CParsedFile.h"
00002 #include "OList.h"
00003 #include <list>
00004
00005 namespace xi {
00006
00007 OListConstruct::OListConstruct(SdagConstruct* single_construct)
00008 : SdagConstruct(SOLIST, single_construct) {
00009 label_str = "olist";
00010 }
00011
00012 OListConstruct::OListConstruct(SdagConstruct* single_construct, SListConstruct* tail)
00013 : SdagConstruct(SOLIST, single_construct, tail) {
00014 label_str = "olist";
00015 }
00016
00017 void OListConstruct::generateCode(XStr& decls, XStr& defs, Entry* entry) {
00018 generateClosureSignature(decls, defs, entry, false, "void", label, false, encapState);
00019 defs << " SDAG::CCounter *" << counter << "= new SDAG::CCounter("
00020 << (int)constructs->size() << ");\n";
00021
00022 for (std::list<SdagConstruct*>::iterator it = constructs->begin();
00023 it != constructs->end(); ++it) {
00024 defs << " ";
00025 generateCall(defs, encapStateChild, encapStateChild, (*it)->label);
00026 }
00027 endMethod(defs);
00028
00029 sprintf(nameStr, "%s%s", CParsedFile::className->charstar(), label->charstar());
00030 strcat(nameStr, "_end");
00031 #if CMK_BIGSIM_CHARM
00032 defs << " CkVec<void*> " << label << "_bgLogList;\n";
00033 #endif
00034
00035 generateClosureSignature(decls, defs, entry, false, "void", label, true,
00036 encapStateChild);
00037 #if CMK_BIGSIM_CHARM
00038 generateBeginTime(defs);
00039 defs << " " << label << "_bgLogList.insertAtEnd(_bgParentLog);\n";
00040 #endif
00041
00042 defs << " " << counter << "->decrement();\n";
00043
00044 #ifdef USE_CRITICAL_PATH_HEADER_ARRAY
00045 defs << " olist_" << counter
00046 << "_PathMergePoint.updateMax(currentlyExecutingPath); /* Critical Path "
00047 "Detection FIXME: is the currently executing path the right thing for this? "
00048 "The duration ought to have been added somewhere. */ \n";
00049 #endif
00050
00051 defs << " if (" << counter << "->isDone()) {\n";
00052
00053 #ifdef USE_CRITICAL_PATH_HEADER_ARRAY
00054 defs << " currentlyExecutingPath = olist_" << counter
00055 << "_PathMergePoint; /* Critical Path Detection */ \n";
00056 defs << " olist_" << counter
00057 << "_PathMergePoint.reset(); /* Critical Path Detection */ \n";
00058 #endif
00059
00060 defs << " " << counter << "->deref();\n";
00061
00062 #if CMK_BIGSIM_CHARM
00063 generateListEventBracket(defs, SOLIST_END);
00064 defs << " " << label << "_bgLogList.length()=0;\n";
00065 #endif
00066
00067 defs << " ";
00068 generateCall(defs, encapState, encapState, next->label, nextBeginOrEnd ? 0 : "_end");
00069 defs << " }\n";
00070 endMethod(defs);
00071
00072 generateChildrenCode(decls, defs, entry);
00073 }
00074
00075 void OListConstruct::numberNodes() {
00076 nodeNum = numOlists++;
00077 SdagConstruct::numberNodes();
00078 }
00079
00080 void OListConstruct::propagateState(std::list<EncapState*> encap,
00081 std::list<CStateVar*>& plist,
00082 std::list<CStateVar*>& wlist, int uniqueVarNum) {
00083 CStateVar* sv;
00084
00085 stateVars = new std::list<CStateVar*>();
00086
00087 encapState = encap;
00088
00089 stateVarsChildren = new std::list<CStateVar*>(plist);
00090 stateVars->insert(stateVars->end(), plist.begin(), plist.end());
00091 {
00092 char txt[128];
00093 sprintf(txt, "_co%d", nodeNum);
00094 counter = new XStr(txt);
00095 sv = new CStateVar(0, "SDAG::CCounter *", 0, txt, 0, NULL, 1);
00096 sv->isCounter = true;
00097 stateVarsChildren->push_back(sv);
00098
00099 std::list<CStateVar*> lst;
00100 lst.push_back(sv);
00101 EncapState* state = new EncapState(NULL, lst);
00102 state->type = new XStr("SDAG::CCounter");
00103 state->name = new XStr(txt);
00104 encap.push_back(state);
00105 }
00106
00107 encapStateChild = encap;
00108
00109 propagateStateToChildren(encap, *stateVarsChildren, wlist, uniqueVarNum);
00110 }
00111
00112 }