Example #1
0
void IRGenerator::accept(VariableExpr& expr)
{
    FNTRACE();

    // loads the value of the given variable

    if (auto var = scope().lookup(expr.variable())) {
        result_ = createLoad(var);
    } else {
        result_ = nullptr;
    }
}
Example #2
0
void getLoadData(ifstream& input,vector<Load>& vecLoad)
{//读取所有节点或其他信息函数
	if(!input)
		return;
	string str;
	
	while(1)
	{
		str.clear();
		getline(input,str);
		if(str=="<Load::nx type=全数>")
		{
		
			str.clear();
			getline(input,str);
			vector<string> vecLoadHeader=split(str);
			
			int loadVoltColumn(0);//识别表头
			int loadEqColumn(0);
			int loadNodeColumn(0);
			int loadPColumn(0);
			int loadQColumn(0);
			int loadOffColumn(0);
	
			for(size_t t=0;t<vecLoadHeader.size();++t)
			{
				if(vecLoadHeader[t]=="volt")
				{
					loadVoltColumn=t;
				}
				else if(vecLoadHeader[t]=="Eq")
				{
					loadEqColumn=t;
				}
				else if(vecLoadHeader[t]=="node")
				{
					loadNodeColumn=t;
				}
				else if(vecLoadHeader[t]=="P")
				{
					loadPColumn=t;
				}
				else if(vecLoadHeader[t]=="Q")
				{
					loadQColumn=t;
				}
				else if(vecLoadHeader[t]=="off")
				{
					loadOffColumn=t;
				}
		
				else
					continue;
			}
			const int loadVoltColumnConst=loadVoltColumn;
			const int loadEqColumnConst=loadEqColumn;
			const int loadNodeColumnConst=loadNodeColumn;
			const int loadPColumnConst=loadPColumn;
			const int loadQColumnConst=loadQColumn;
			const int loadOffColumnConst=loadOffColumn;
			
			//记录所需要行列的位置

			str.clear();//其中一行数据是不需要的,先清除一行数据
			getline(input,str);
			str.clear();
			getline(input,str);
			
			while(str!="</Load::nx>")
			{
				vector<string> vec=split(str);
				//所有数据都已经存放在vec中,接下来是选出有用数据,对数所进行转换
				int volt=stringToInt(vec[loadVoltColumnConst]);
				int eq=stringToInt(vec[loadEqColumnConst]);
				string node=vec[loadNodeColumnConst];
				double p=stringToDouble(vec[loadPColumnConst]);
				double q=stringToDouble(vec[loadQColumnConst]);
				bool off=stringToBool(vec[loadOffColumnConst]);
				Load load=createLoad(volt,eq,node,p,q,off);
				/*size_t t=0;
				for(;t<vecLoad.size();++t)
				{
					if(vecLoad[t]==load)
					{
						str.clear();
						getline(input,str);
						break;
					}
				}
				if(t<vecLoad.size())continue;*/
				vecLoad.push_back(load);
				
				str.clear();
				getline(input,str);
			}
		}
		if(str=="</Load::nx>")
			break;
	}
}
Example #3
0
void produce(unsigned int n, void *(*func)(void *)) {
  int maxHandle = 8, readyId=-1, nC = 0;
  Heap *wHeap = NULL, *restHeap = NULL;
  wHeap = initHeap(wHeap, loadComp, freeLoad);
  restHeap = initHeap(restHeap, loadComp, freeLoad);
  unsigned int minThreshold = maxHandle > n ? n : maxHandle;
  pthread_t thList[minThreshold];
  pthread_attr_t attr;
  pthread_attr_init(&attr);
#ifdef __linux__
  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
#endif

  for (readyId=0; readyId < minThreshold; ++readyId) {
    unsigned int *iNew = (unsigned int *)malloc(sizeof(unsigned int));
    *iNew = readyId;
    Load *l = createLoad(iNew);
    l->thId = readyId;
    addLoad(wHeap, l);
    pthread_create(thList + readyId, &attr, func, l);
  }

  int i, minFreeLoadCount = minThreshold >> 1;
  if (readyId < n) {
    heapifyFromHead(wHeap);
    i = readyId;
    int chillThId = -1;
    Load *wHead = NULL;
    while (i < n) {
      printf("\033[32mwHeap: "); printHeap(wHeap, printLoad);
      printf("\n\033[33mrHeap: "); printHeap(restHeap, printLoad);
      printf("\ni:%d n:%d chillThId: %d\033[00m\n", i, n, chillThId);

      if ((wHead = peek(wHeap)) != NULL) {
        printf("wHead: %d\n", wHead->id);

        void *data = NULL;
        int join = pthread_join(thList[wHead->thId], &data);
        printf("newJoin: %d\n", join);
        if (! join) {
          printf("joined: %d\n", wHead->thId);
          if (data != NULL) {
            printf("\033[36m\nRetr %s :%d\033[00m\n", (char *)data, wHead->thId); 
            free(data);
          }
          chillThId = wHead->thId;
          printf("chillThId: %d\n", chillThId);
        #ifdef DEBUG
          printf("wHead->thId: %d\n", wHead->thId);
        #endif
          heapExtract(wHeap, (const void **)&wHead); 
          wHead->id = getAvailableId(restHeap);
          addLoad(restHeap, wHead); 
          printf("rHeap"); printHeap(restHeap, printLoad);
          wHead = NULL;
        }
      }

      if (getSize(wHeap) < minFreeLoadCount && peek(restHeap) != NULL) {
      #ifdef DEBUG
        printf("Peeked: %p\n", peek(restHeap));
        printf("\nrestHeap\n");
      #endif
        heapExtract(restHeap, (const void **)&wHead);
        if (wHead == NULL) continue;
      #ifdef DEBUG
        printf("wHead->thId:: %p\n", wHead);
      #endif
        wHead->thId = chillThId;
        *((int *)wHead->data) = i;

        addLoad(wHeap, wHead);
        int createStatus =\
          pthread_create(thList + wHead->thId, &attr, func, wHead);
        printf("createdStatus: %d i: %d\n", createStatus, i);
        if (! createStatus) {
          ++i;
        }
      }
    }
  }

  while (! isEmpty(wHeap)) {
    Load *tmpHead = NULL;
    if (! heapExtract(wHeap, (const void **)&tmpHead) && tmpHead != NULL) {
      void *data = NULL;
      if (! pthread_join(thList[tmpHead->thId], &data)) {
        if (data != NULL) {
          printf("i: %d Joined msg: %s\n", i, (char *)data);
          free(data);
        }
      }
    }
    freeLoad(tmpHead);
  }

  destroyHeap(wHeap);
  destroyHeap(restHeap);
}