//adds a background job to the end of the list of background jobs void addToJobs(pid_t newPid, char *newCommand) { struct jobNode *newJob = createNewJob(newPid, newCommand); //if the list is empty, set the head's information to that of the new job if (head == NULL) { head = newJob; return; } //otherwise, move a pointer to the end of the list struct jobNode *crt = head; while (crt->next != NULL) crt = crt->next; crt->next = newJob; newJob->prev = crt; }
/* * Precondition: job_queue.size() > 0 && num_free_slaves > 0 * */ bool Master::sendJob() { if (PAR_DEBUG) fprintf(stderr, "Finding free slave\n"); profile_start(); // Find empty worker int thread_no = -1; for(int i = 0 ; i < num_threads ; i++){ if(job_start_time[i] == NOT_WORKING){ thread_no = i; break; } } assert(thread_no >= 0 && "Did not find an idle worker?"); // Decide which job to send. int job_num = -1; if(so.purePortfolio){ if(slaveStates[thread_no] == NORMAL_SEARCH){ job_num = job_queue.size() - 1; } else{ // Create a job with random bound... if (createNewJob(thread_no, so.random_split)) job_num = job_queue.size() - 1; else{ setState(thread_no, NORMAL_SEARCH); slaveStates[thread_no] = NORMAL_SEARCH; slavesRunningGreedy--; job_num = selectJob(thread_no); } } } else{ // Work stealing if(slaveStates[thread_no] == NORMAL_SEARCH){ job_num = selectJob(thread_no); } else if(slaveStates[thread_no] == PORTFOLIO_SEARCH){ job_queue.push(new SClause()); job_num = job_queue.size() - 1; } else{ // Create a new job with random bound if(createNewJob(thread_no, so.random_split)) job_num = job_queue.size() - 1; else{ // Okay, no more initialization... setState(thread_no, NORMAL_SEARCH); slaveStates[thread_no] = NORMAL_SEARCH; slavesRunningGreedy--; job_num = selectJob(thread_no); } } } num_free_slaves--; job_start_time[thread_no] = wallClockTime(); //if(!foundJob) // job_num = selectJob(thread_no); assert(thread_no < num_threads); assert(thread_no >= 0); assert(job_num < job_queue.size()); assert(job_num >= 0); if (cur_job[thread_no]) free(cur_job[thread_no]); cur_job[thread_no] = job_queue[job_num]; job_queue[job_num] = job_queue.last(); job_queue.pop(); if (PAR_DEBUG) fprintf(stderr, "Sending job of size %d to %d , job_queue.size()=%d\n", cur_job[thread_no]->size, thread_no, job_queue.size() ); MPI_Request r; MPI_Isend((int*) cur_job[thread_no], cur_job[thread_no]->memSize(), MPI_INT, thread_no+1, JOB_TAG, MPI_COMM_WORLD, &r); MPI_Request_free(&r); if (PROFILING && job_queue.size() <= 4) fprintf(stderr, "Number of jobs left in queue: %d\n", job_queue.size()); return true; }