Пример #1
0
  @Override
  public void taskJoin(int thrdId, int taskId) {
    RaceTask task = lookup2(root, taskId);
    RaceTaskOOB taskOOB = (RaceTaskOOB) task;
    if (taskOOB == null) {
      System.out.println("[race]join:can not find the child task in the tree!");
      print(root, false);
      System.exit(-1);
    }

    // print(task, false);
    if (!(RaceDetector.itrOn && taskOOB.parent.type == RaceTask.RACE_TASK_DOTALL)) {
      for (int i = 0; i < task.children.size(); i++) {
        RaceTaskOOB right = (RaceTaskOOB) task.children.get(i);
        if (right.type == RaceTask.RACE_TASK_STEP) {
          right.set.setMergeNum(1);
          if (right.set instanceof AccessSetList) {
            taskOOB.set = taskOOB.set.merge(right.set);
          } else {
            right.set.setTaskId(AccessSet.LOG_WORK_MERGE);
            taskOOB.pushSet(right.set);
          }
        }
        right.set = null;
      }
    }
    // push the local set to the pending list
    if (taskOOB.set.getMergeNum() > 0) {
      taskOOB.set.setWorkType(AccessSet.LOG_WORK_HYBRID);
      taskOOB.pushSet(taskOOB.set);
    }
    taskOOB.asyncJoined = true;
    threadTasks.set(thrdId, null);
  }
Пример #2
0
  // public static long[] itrNum = new long[1024];
  // private RaceSet preItrSet = null;
  @Override
  public void startNewItr(long itr) {

    if (!RaceDetector.itrOn) return;

    int thrdId = Scheduler.getCurrThId();
    // itrNum[thrdId * 16]++;
    RaceTask step = threadTasks.get(thrdId);

    if (step == null) {
      System.out.println("[race]startNewItr:can not find the child task in the tree!");
      print(root, false);
      System.exit(-1);
    }
    RaceTaskOOB async = (RaceTaskOOB) step.parent;
    if (async == null) {
      System.out.println("[race]startNewItr:can not find the parent task in the tree!");
      print(root, false);
    }

    // async.asyncItrNum++;

    // if the async node has only one child
    if (async.children.size() - async.delayedNum == 1) {
      // step.set.print();
      step.set.setMergeNum(1);
      // if it is a list set, then we perform intersection and merge
      // immediately using current thread
      if (step.set instanceof AccessSetList) {
        async.set = async.set.intersectAndMerge(step.set, RaceTask.RACE_TASK_ASYNC);
        step.set.clear();
      } else {
        step.set.setWorkType(AccessSet.LOG_WORK_HYBRID);
        async.pushSet(step.set);
        step.reAllocaLog();
        taskMap(Scheduler.getCurrThId(), step);
      }
    } else {
      // System.out.println("new created");
      // create a new asyn node to hold all the children and sets of
      // current iteration
      RaceTaskOOB newAsync =
          new RaceTaskOOB(async.id, RaceTask.RACE_TASK_ASYNC, async.depth + 1, async);
      // set the asyncItrNum, so that newAsync when all the logs are merged together
      newAsync.asyncItrNum = async.children.size() - async.delayedNum;
      // add newAsync as one of the child of async
      async.children.add((int) async.delayedNum, newAsync);
      // remeber how many iterations are delayed for async
      async.delayedNum++;
      // post all sets of step nodes to newAsync
      // add all the finish children of current iteration to newAsync
      for (int i = async.delayedNum; i < async.children.size(); i++) {
        // newAsync.asyncItrNum++;
        RaceTaskOOB bgTask = (RaceTaskOOB) async.children.get(i);
        if (bgTask.type == RaceTask.RACE_TASK_STEP) {
          bgTask.set.setMergeNum(1);
          // if it is a list set, intersection and merge are performed
          // immediately by current thread
          if (bgTask.set instanceof AccessSetList) {
            newAsync.set = newAsync.set.merge(bgTask.set);
          } else {
            bgTask.set.setWorkType(AccessSet.LOG_WORK_MERGE);
            newAsync.pushSet(bgTask.set);
          }
          bgTask.set = null;
        } else {
          newAsync.children.add(bgTask);
          bgTask.parent = newAsync;
          bgTask.depth = newAsync.depth + 1;
        }
      }
      // push itself into the pending queue
      if (newAsync.set.getMergeNum() > 0) {
        newAsync.pushSet(newAsync.set);
      }
      // remove all the children of current iteration from async
      while (async.children.size() - async.delayedNum > 0)
        async.children.remove(async.children.size() - 1);
      // init the first step node for next iteration

      if (step.set instanceof AccessSetList) {
        step.set.clear();
      } else {
        step.reAllocaLog();
      }
      async.children.add(step);
      taskMap(Scheduler.getCurrThId(), step);
    }
  }