Skip to content
Snippets Groups Projects
Commit befe05f1 authored by Martina Maggio's avatar Martina Maggio
Browse files

parallel working

parent 2c944d0a
Branches
No related tags found
No related merge requests found
...@@ -475,29 +475,7 @@ void compute_responsetimes() { ...@@ -475,29 +475,7 @@ void compute_responsetimes() {
sequences.push_back(control_jobs); sequences.push_back(control_jobs);
} }
// ******************************************************************* void process_ntasks(int i, int ntasks, vector<Task> tasks, vector<Task> hps) {
int main(int argc, char *argv[])
{
pid_t child_pid, wpid;
int status = 0;
unsigned int ntasks_sel[3] = {5, 10, 20};
vector<Task> tasks;
vector<Task> hps;
// Generate periods in bucket
generate_bucket();
cout << "------------------------------------------------" << endl;
// number of tasks {5, 10, 20}
for (unsigned int i = 0; i <= 2; i++) {
if ((child_pid = fork()) == 0) {
ntasks = ntasks_sel[i];
unsigned int control_task_id = ntasks - 1; unsigned int control_task_id = ntasks - 1;
// utilization {0.7, 0.80} // utilization {0.7, 0.80}
...@@ -649,11 +627,62 @@ int main(int argc, char *argv[]) ...@@ -649,11 +627,62 @@ int main(int argc, char *argv[])
//cout << "------------------------------------------------" << endl; //cout << "------------------------------------------------" << endl;
} }
} }
}
// *******************************************************************
int main(int argc, char *argv[])
{
int num_numtasks = 3;
int i;
pid_t pid;
unsigned int ntasks_sel[3] = {5, 10, 20};
vector<Task> tasks;
vector<Task> hps;
// Generate periods in bucket
generate_bucket();
cout << "------------------------------------------------" << endl;
// number of tasks {5, 10, 20}
//for (unsigned int i = 0; i <= 2; i++) {
pid = fork();
if (pid == 0) {
i = 0;
ntasks = ntasks_sel[i];
cout <<"[worker] pid " << getpid() << " from [parent] pid " << getppid() << " processing " << ntasks << endl;
process_ntasks(i, ntasks, tasks, hps);
cout <<"[worker] pid " << getpid() << " from [parent] pid " << getppid() << " terminated " << ntasks << endl;
exit(0);
}
else {
pid = fork();
if (pid == 0) {
i = 1;
ntasks = ntasks_sel[i];
cout <<"[worker] pid " << getpid() << " from [parent] pid " << getppid() << " processing " << ntasks << endl;
process_ntasks(i, ntasks, tasks, hps);
cout <<"[worker] pid " << getpid() << " from [parent] pid " << getppid() << " terminated " << ntasks << endl;
exit(0); exit(0);
}
else {
pid = fork();
if (pid == 0) {
i = 2;
ntasks = ntasks_sel[i];
cout <<"[worker] pid " << getpid() << " from [parent] pid " << getppid() << " processing " << ntasks << endl;
process_ntasks(i, ntasks, tasks, hps);
cout <<"[worker] pid " << getpid() << " from [parent] pid " << getppid() << " terminated " << ntasks << endl;
exit(0);
} }
while ((wpid = wait(&status)) > 0) { else
printf("Thread %d completed sequence generation\n", (int) wpid); for (int thr = 0; thr < 3; thr++) wait(NULL);
} }
} }
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment