| 1057 | } |
| 1058 | |
| 1059 | Task* NextTask() |
| 1060 | { |
| 1061 | if (!this->HasData[Rank]) |
| 1062 | { |
| 1063 | return nullptr; |
| 1064 | } |
| 1065 | |
| 1066 | //--------------------------------------------------------- |
| 1067 | // Send messages |
| 1068 | //--------------------------------------------------------- |
| 1069 | |
| 1070 | while (!this->PTasks.empty()) |
| 1071 | { |
| 1072 | vtkSmartPointer<Task> task = PTasks.back(); |
| 1073 | PTasks.pop_back(); |
| 1074 | |
| 1075 | if (task->GetTraceTerminated()) |
| 1076 | { |
| 1077 | // send to the master process |
| 1078 | this->Send(TaskFinished, this->Leader, task); |
| 1079 | } |
| 1080 | else |
| 1081 | { |
| 1082 | if (!task->GetTraceExtended()) |
| 1083 | { |
| 1084 | // increment the peak |
| 1085 | task->NumPeeks++; |
| 1086 | PRINT("Skip " << task->GetId() << " with " << task->NumPeeks << " Peeks"); |
| 1087 | } |
| 1088 | else |
| 1089 | { |
| 1090 | task->NumPeeks = 1; |
| 1091 | } |
| 1092 | int nextProcess = -1; |
| 1093 | if (task->NumPeeks < this->NumProcs) |
| 1094 | { |
| 1095 | nextProcess = NextProcess(task); |
| 1096 | if (nextProcess >= 0) |
| 1097 | { |
| 1098 | task->IncHop(); |
| 1099 | // send it to the next guy |
| 1100 | this->Send(NewTask, NextProcess(task), task); |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | if (nextProcess < 0) |
| 1105 | { |
| 1106 | this->Send(TaskFinished, this->Leader, task); // no one can do it, norminally finished |
| 1107 | PRINT("Bail on " << task->GetId()); |
| 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | //--------------------------------------------------------- |
| 1113 | // Receive messages |
| 1114 | //--------------------------------------------------------- |
| 1115 | |
| 1116 | do |