예제 #1
0
파일: array.c 프로젝트: jdetomasi/nachos
int main (){
    int sum;

    verify_array(48);
    sum = add_array(48);
    verify_array(48);

    Exit(sum);
}
예제 #2
0
파일: qsort.c 프로젝트: emersonp/515assign1
// Main routine for testing quicksort
// 
int main(int argc, char **argv) {
  int *array, N;
  
  // check command line first 
  if (argc < 2) {
    printf ("Usage: ./qsort <N>\n");
    exit(0);
  }
  if ((N = atoi(argv[1])) < 2) {
    printf ("<N> must be greater than 2\n");
    exit(0);
  }

  array = init_array(N);

  printf("Sorting started ...\n");
  quicksort(array, 0, N-1);
  printf("... completed.\n");

  verify_array(array, N);
}
// Main routine for testing quicksort
//
int main(int argc, char **argv) {
    int N;
  //  time_t start, initT, qsortT, verifyT, fullT;

 //   start = time(NULL);

    // check command line first
    if (argc < 2) {
        printf("Usage: ./qsort <N> [<numConsumers>]\n");
        exit(0);
    }

    // at least 1 argument
    if (argc >= 2) {
        if ((N = atoi(argv[1])) < 2) {
            printf("<N> must be greater than 2\n");
            exit(0);
        }
    }

    // more than one argument, save second and ignore the rest
    if (argc > 2) {
        if ((numConsumers = atoi(argv[2])) < 1) {
            printf("<N> must be greater than 0\n");
            exit(0);
        }
    }

    // Initialization section
    pthread_t thread[numConsumers];
    array = init_array(N);
//    initT = time(NULL);
    sharedQueue = init_queue(0);
    initialTask = create_task(0, N-1);

    // numberOfProducers is a termination conditions, so set it to 1, so other threads
    // don't quit prematurely
    numberOfProducers = 1;

    pthread_mutex_init(&taskLock, NULL);   /* initialize mutex */
    pthread_mutex_init(&clientLock, NULL);   /* initialize mutex */

    for (long k = 0; k < numConsumers -1; k++) {
        pthread_create(&thread[k], NULL, (void *) consumer, (void *) k);
    }

    // the main thread also runs a copy of the consumer() routine;
    // its copy has the last id, numConsumers-1
    consumer(numConsumers - 1);
    //printf("Joining threads\n");
    // the main thread waits for consumer threads to join back
    for (long k = 0; k < numConsumers -1; k++)
        pthread_join(thread[k], NULL);

    pthread_mutex_destroy(&taskLock);
    pthread_mutex_destroy(&clientLock);

   // qsortT =time(NULL);
    verify_array(array, N);
  //  verifyT =time(NULL);

   // fullT = verifyT - start;
   //  verifyT = verifyT - qsortT;
   // qsortT = qsortT - initT;
   // initT = initT - start;
   // printf("realI    %.3f s\n", SEC(fullT));
   // printf("initT    %.3f s ratio %.3f\n", SEC(initT),SEC(initT)/SEC(fullT));
   // printf("qsortT   %.3f s ratio %.3f\n", SEC(qsortT),SEC(qsortT)/SEC(fullT));
   // printf("verifyT  %.3f s ratio %.3f\n", SEC(verifyT),SEC(verifyT)/SEC(fullT));
    free(array);
    free(sharedQueue);
}