Exemplo n.º 1
0
int main (int argc, char *argv[])
{
#if defined(USE_LFH) && defined(_WIN32)
  // Activate 'Low Fragmentation Heap'.
  ULONG info = 2;
  HeapSetInformation (GetProcessHeap(),
		      HeapCompatibilityInformation,
		      &info,
		      sizeof(info));
#endif
#if 0 // defined(__SVR4)
 {
   psinfo_t ps;
   int pid = getpid();
   char fname[255];
   sprintf (fname, "/proc/%d/psinfo", pid);
   // sprintf (fname, "/proc/self/ps");
   FILE * f = fopen (fname, "rb");
   printf ("opening %s\n", fname);
   if (f) {
     fread (&ps, sizeof(ps), 1, f);
     printf ("resident set size = %dK\n", ps.pr_rssize);
     fclose (f);
   }
 }
#endif

#if defined(_MT) || defined(_REENTRANT)
  int          min_threads, max_threads ;
  int          num_rounds ;
  int          chperthread ;
#endif
  unsigned     seed=12345 ;
  int          num_chunks=10000;
  long sleep_cnt;

  if (argc > 7) {
    sleep_cnt = atoi(argv[1]);
    min_size = atoi(argv[2]);
    max_size = atoi(argv[3]);
    chperthread = atoi(argv[4]);
    num_rounds = atoi(argv[5]);
    seed = atoi(argv[6]);
    max_threads = atoi(argv[7]);
    min_threads = max_threads;
    printf ("sleep = %ld, min = %d, max = %d, per thread = %d, num rounds = %d, seed = %d, max_threads = %d, min_threads = %d\n",
	    sleep_cnt, min_size, max_size, chperthread, num_rounds, seed, max_threads, min_threads);
    goto DoneWithInput;
  }

#if defined(_MT) || defined(_REENTRANT)
  //#ifdef _MT
  printf( "\nMulti-threaded test driver \n") ;
#else
  printf( "\nSingle-threaded test driver \n") ;
#endif
#ifdef CPP
  printf("C++ version (new and delete)\n") ;
#else
  printf("C version (malloc and free)\n") ;
#endif
  printf("runtime (sec): ") ;
  scanf ("%ld", &sleep_cnt);

  printf("chunk size (min,max): ") ;
  scanf("%d %d", &min_size, &max_size ) ;
#if defined(_MT) || defined(_REENTRANT)
  //#ifdef _MT
  printf("threads (min, max):   ") ; 
  scanf("%d %d", &min_threads, &max_threads) ;
  printf("chunks/thread:  ") ; scanf("%d", &chperthread ) ;
  printf("no of rounds:   ") ; scanf("%d", &num_rounds ) ;
  num_chunks = max_threads*chperthread ;
#else 
  printf("no of chunks:  ") ; scanf("%d", &num_chunks ) ;
#endif
  printf("random seed:    ") ; scanf("%d", &seed) ;

 DoneWithInput:

  if( num_chunks > MAX_BLOCKS ){
    printf("Max %d chunks - exiting\n", MAX_BLOCKS ) ;
    return(1) ;
  }

#ifndef __WIN32__
#ifdef __SVR4
  pthread_setconcurrency (max_threads);
#endif
#endif

  lran2_init(&rgen, seed) ;
  // init_space = CountReservedSpace() ;

#if defined(_MT) || defined(_REENTRANT)
  //#ifdef _MT
  runthreads(sleep_cnt, min_threads, max_threads, chperthread, num_rounds) ;
#else
  runloops(sleep_cnt, num_chunks ) ;
#endif

#ifdef _DEBUG
  _cputs("Hit any key to exit...") ;	(void)_getch() ;
#endif

  return 0;

} /* main */
Exemplo n.º 2
0
Arquivo: larson.c Projeto: d-b/CSC469
int main (int argc, char *argv[])
{

#if defined(_MT) || defined(_REENTRANT)
  int          min_threads, max_threads ;
  int          num_rounds ;
  int          chperthread ;
#endif
  unsigned     seed=12345 ;
  int          num_chunks=10000;
  long sleep_cnt;
  int matches;

  if (argc > 7) {
    sleep_cnt = atoi(argv[1]);
    min_size = atoi(argv[2]);
    max_size = atoi(argv[3]);
    chperthread = atoi(argv[4]);
    num_rounds = atoi(argv[5]);
    seed = atoi(argv[6]);
    max_threads = atoi(argv[7]);
    min_threads = max_threads;
    goto DoneWithInput;
  }

#if defined(_MT) || defined(_REENTRANT)
  //#ifdef _MT
  printf( "\nMulti-threaded test driver \n") ;
#else
  printf( "\nSingle-threaded test driver \n") ;
#endif
  printf("C version (malloc and free)\n") ;

  printf("runtime (sec): ") ; /* 15 seconds */
  if ((matches = scanf ("%ld", &sleep_cnt)) != 1) {
	  printf("error scanning stdin for sleep_cnt - exiting\n");
	  return(1);
  }

  printf("chunk size (min,max): ") ; /* 8 40 */
  if ((matches = scanf("%d %d", &min_size, &max_size )) != 2) {
	  printf("error scanning stdin for chunk size (min,max) - exiting\n");
	  return(1);
  }

#if defined(_MT) || defined(_REENTRANT)
  //#ifdef _MT
  printf("threads (min, max):   ") ; /* same, 1 1, 2 2, etc. */
  if ((matches = scanf("%d %d", &min_threads, &max_threads)) != 2) {
	  printf("error scanning stdin for threads (min,max) - exiting\n");
	  return(1);
  }

  printf("chunks/thread:  ") ; 
  if ((matches = scanf("%d", &chperthread )) != 1) { /* 10K */
	  printf("error scanning stdin for chunks/thread - exiting\n");
	  return(1);
  }
	  
  printf("no of rounds:   ") ; 
  if ((matches = scanf("%d", &num_rounds )) != 1) {  /* 10 */
	  printf("error scanning stdin for no of rounds - exiting\n");
	  return(1);
  }
  num_chunks = max_threads*chperthread ;
#else 
  printf("no of chunks:  ") ; 
  if ((matches = scanf("%d", &num_chunks )) != 1) {
	  printf("error scanning stdin for no of chunks - exiting\n");
	  return(1);
  }	  
#endif
  printf("random seed:    ") ; 
  if ((matches = scanf("%d", &seed)) != 1) {
	  printf("error scanning stdin for random seed - exiting\n");
	  return(1);
  }	  	  
  printf("\n");
 DoneWithInput:

  if( num_chunks > MAX_BLOCKS ){
    printf("Max %d chunks - exiting\n", MAX_BLOCKS ) ;
    return(1) ;
  }

  pthread_setconcurrency (max_threads);

  lran2_init(&rgen, seed) ;

  // Call allocator-specific initialization function
  mm_init();

  numCPU=getNumProcessors();

#if defined(_MT) || defined(_REENTRANT)
  //#ifdef _MT
  runthreads(sleep_cnt, min_threads, max_threads, chperthread, num_rounds) ;
#else
  runloops(sleep_cnt, num_chunks ) ;
#endif

#ifdef _DEBUG
  _cputs("Hit any key to exit...") ;	(void)_getch() ;
#endif


  return(0) ;

} /* main */