int main(int argc, char ** argv)
{
    time_t start, end;
    time_t run_time;
    unsigned long i;
    pid_t pids[NUM_OF_CORES];

    /* start of test */
    start = time(NULL);
    for (i = 0; i < NUM_OF_CORES; ++i) {
        if (!(pids[i] = fork())) {
            do_primes();
            exit(0);
        }
        if (pids[i] < 0) {
            perror("Fork");
            exit(1);
        }
    }
    for (i = 0; i < NUM_OF_CORES; ++i) {
        waitpid(pids[i], NULL, 0);
    }
    end = time(NULL);
    run_time = (end - start);
    printf("This machine calculated all prime numbers under %d %d times "
           "in %d seconds\n", MAX_PRIME, NUM_OF_CORES, run_time);
    return 0;
}
Example #2
0
int main(int argc, char ** argv)
{
    int numCores, maxPrime;

    if (argc < 3) {
      printf("Not enough arguments. arg 1 = NUM_OF_CORES. arg 2 = MAX_PRIME\n");
      printf("Example: ./a.out 4 1000\n");
      printf("Switching to default values for Cores: %d and Max Prime: %d\n", NUM_OF_CORES, MAX_PRIME);

      numCores = NUM_OF_CORES;
      maxPrime = MAX_PRIME;
    }
    else {
      numCores = atoi(argv[1]);
      maxPrime = atoi(argv[2]);

      printf("Began CPU load test with %d cores and the max prime being %d\n",
        numCores, maxPrime);
    }

    time_t start, end;
    time_t run_time;
    unsigned long i;
    pid_t pids[numCores];

    /* start of test */
    start = time(NULL);
    for (i = 0; i < numCores; ++i) {
        if (!(pids[i] = fork())) {
            do_primes(maxPrime);
            exit(0);
        }
        if (pids[i] < 0) {
            perror("Fork");
            exit(1);
        }
    }
    for (i = 0; i < numCores; ++i) {
        waitpid(pids[i], NULL, 0);
    }
    end = time(NULL);
    run_time = (end - start);
    printf("This machine calculated all prime numbers under %d, %d times "
           "in %ld seconds\n", maxPrime, numCores, run_time);

    return 0;
}
Example #3
0
int main(int argc, char **argv)
{

	pid_t pid;
    int i;

    int policy;
    struct sched_param param;

    if (argc != 2){
       perror("incorrect arguments");
       exit(0);
    }

    if (!strcmp(argv[1], "SCHED_OTHER")) {
         policy = SCHED_OTHER;
    }
    else if(!strcmp(argv[1], "SCHED_FIFO")){
         policy = SCHED_FIFO;
    }
    else if (!strcmp(argv[1], "SCHED_RR")){
         policy = SCHED_RR;
    }
    else{
         perror("Scheduling policy not understood\n");
         exit(EXIT_FAILURE);
    }

    /* set process to max priority for given scheduler */
     param.sched_priority = sched_get_priority_max(policy);

     if(sched_setscheduler(0,policy,&param)){
         perror("Error setting scheduler policy");
         exit(EXIT_FAILURE);
     }
	   while(1)
	   {
			 do_primes();
           sleep(1);

	   }

   return 0;
}