Example #1
0
void main()
{
 int key[20];
 int id[50];
 int scores[50];
 int ans[20];
 float avg;
 int nq,ns,oid;
 clrscr();
 ns = 0;
 /*input number of questions on test*/
 scanf("%d",&nq);
 /*input answer key*/
 inputarray(key,nq);
 while(scanf("%d",&oid) != EOF)
  {
	/*input individual students scores*/
	inputarray(ans,nq);
	/*store id number aquired earlier in scanf in id[]*/
	id[ns] = oid;
	/*score individual students test*/
	scores[ns] = scoretest(key,ans,nq);
	ns++;

  }
 /*calculate average score for entire class*/
 avg = average(scores,ns);
 /*sort class scores in descending order*/
 sortscores(scores,id,ns);
 /*output results to screen*/
 printresults(id,scores,avg,ns);
}
Example #2
0
int main(){
    FILE *f;
    int class;
    size_t c;
    f = fopen("./c.txt", "r");
    c = 0;
    while(EOF != fscanf(f,"%d",&class)){
        increment(class);
    }
    fclose(f);
    printresults(c);
}
int main(int argc, char* argv[])
{
    unsigned long int min_sz=800000, max_sz = 0, step_sz = 10000;
		int min_ratio=50, max_ratio = 0, step_ratio = 1;
		int arg,i,j,v;
		int no_exp;

		for(arg = 1;arg<argc;arg++){
			if(0==strcmp("-d",argv[arg])){
				debug = 1;
			}
			if(0==strcmp("-l",argv[arg])){
					min_sz = atoi(argv[arg+1]);
					if(arg+2>=argc) break;
					if(0==strcmp("-r",argv[arg+2])) break;
					if(0==strcmp("-d",argv[arg+2])) break;
					max_sz = atoi(argv[arg+2]);
					step_sz = atoi(argv[arg+3]);
			}
			if(0==strcmp("-r",argv[arg])){
					min_ratio = atoi(argv[arg+1]);
					if(arg+2>=argc) break;
					if(0==strcmp("-l",argv[arg+2])) break;
					if(0==strcmp("-d",argv[arg+2])) break;
					max_ratio = atoi(argv[arg+2]);
					step_ratio = atoi(argv[arg+3]);
			}

		}
    for(v=0; toupperversion[v].func !=0; v++)
		no_version=v+1;
		if(0==max_sz)  no_sz =1;
		else no_sz = (max_sz-min_sz)/step_sz+1;
		if(0==max_ratio)  no_ratio =1;
		else no_ratio = (max_ratio-min_ratio)/step_ratio+1;
		no_exp = v*no_sz*no_ratio;
		results = (double *)malloc(sizeof(double[no_exp]));
		ratios = (double *)malloc(sizeof(double[no_ratio]));
		sizes = (long *)malloc(sizeof(long[no_sz]));

		for(i=0;i<no_sz;i++)
			sizes[i] = min_sz + i*step_sz;
		for(i=0;i<no_ratio;i++)
			ratios[i] = min_ratio + i*step_ratio;

		for(i=0;i<no_sz;i++)
			for(j=0;j<no_ratio;j++)
				run(i,j);

		printresults();
    return 0;
}
Example #4
0
int main(void) {
    pthread_mutex_init(&mutex, NULL);
    FILE*file1, *file2, *file3, *file4, *file5;
    int end=0;  
    file1=fopen("drive1.data", "r");
    file2=fopen("drive2.data", "r");
    file3=fopen("drive3.data", "r");
    file4=fopen("drive4.data", "r");
    file5=fopen("drive5.data", "r");
    one.file=file1;
    two.file=file2;
    three.file=file3;
    four.file=file4;
    five.file=file5;
    one.num=0;
    two.num=1;
    three.num=2;
    four.num=3;
    five.num=4;

    pthread_t thread1, thread2, thread3, thread4, thread5;
    pthread_create(&thread1, NULL, (void*)&read_thread, (void*)&one);
    pthread_detach(thread1);
    pthread_create(&thread2, NULL, (void*)&read_thread, (void*)&two);
    pthread_detach(thread2);
pthread_create(&thread3, NULL, (void*)&read_thread, (void*)&three);
    pthread_detach(thread3);
    pthread_create(&thread4, NULL, (void*)&read_thread, (void*)&four);
    pthread_detach(thread4);
    pthread_create(&thread5, NULL, (void*)&read_thread, (void*)&five);
    pthread_detach(thread5);

    printresults();

    pthread_exit(&end);
    fclose(file1);
    fclose(file2);
    fclose(file3);
    fclose(file4);
    fclose(file5);

    return 0;
}
Example #5
0
/**************
 * Main routine
 **************/
int main(int argc, char **argv) {
    int i;
    char c;
    char **tracefiles = NULL;  /* null-terminated array of trace file names */
    int num_tracefiles = 0;    /* the number of traces in that array */
    trace_t *trace = NULL;     /* stores a single trace file in memory */
    range_t *ranges = NULL;    /* keeps track of block extents for one trace */
    stats_t *libc_stats = NULL;/* libc stats for each trace */
    stats_t *mm_stats = NULL;  /* mm (i.e. student) stats for each trace */
    speed_t speed_params;      /* input parameters to the xx_speed routines */ 

    int run_libc = 0;    /* If set, run libc malloc (set by -l) */
    int autograder = 0;  /* If set, emit summary info for autograder (-g) */

    /* temporaries used to compute the performance index */
    double secs, ops, util, avg_mm_util, avg_mm_throughput, p1, p2, perfindex;
    int numcorrect;
    
    /* 
     * Read and interpret the command line arguments 
     */
    while ((c = getopt(argc, argv, "f:t:hvVgal")) != EOF) {
        switch (c) {
	case 'g': /* Generate summary info for the autograder */
	    autograder = 1;
	    break;
        case 'f': /* Use one specific trace file only (relative to curr dir) */
            num_tracefiles = 1;
            if ((tracefiles = realloc(tracefiles, 2*sizeof(char *))) == NULL)
		unix_error("ERROR: realloc failed in main");
	    strcpy(tracedir, "./"); 
            tracefiles[0] = strdup(optarg);
            tracefiles[1] = NULL;
            break;
	case 't': /* Directory where the traces are located */
	    if (num_tracefiles == 1) /* ignore if -f already encountered */
		break;
	    strcpy(tracedir, optarg);
	    if (tracedir[strlen(tracedir)-1] != '/') 
		strcat(tracedir, "/"); /* path always ends with "/" */
	    break;
        case 'l': /* Run libc malloc */
            run_libc = 1;
            break;
        case 'v': /* Print per-trace performance breakdown */
            verbose = 1;
            break;
        case 'V': /* Be more verbose than -v */
            verbose = 2;
            break;
        case 'h': /* Print this message */
	    usage();
            exit(0);
        default:
	    usage();
            exit(1);
        }
    }
    
    

    /* 
     * If no -f command line arg, then use the entire set of tracefiles 
     * defined in default_traces[]
     */
    if (tracefiles == NULL) {
        tracefiles = default_tracefiles;
        num_tracefiles = sizeof(default_tracefiles) / sizeof(char *) - 1;
	printf("Using default tracefiles in %s\n", tracedir);
    }

    /* Initialize the timing package */
    init_fsecs();

    /*
     * Optionally run and evaluate the libc malloc package 
     */
    if (run_libc) {
	if (verbose > 1)
	    printf("\nTesting libc malloc\n");
	
	/* Allocate libc stats array, with one stats_t struct per tracefile */
	libc_stats = (stats_t *)calloc(num_tracefiles, sizeof(stats_t));
	if (libc_stats == NULL)
	    unix_error("libc_stats calloc in main failed");
	
	/* Evaluate the libc malloc package using the K-best scheme */
	for (i=0; i < num_tracefiles; i++) {
	    trace = read_trace(tracedir, tracefiles[i]);
	    libc_stats[i].ops = trace->num_ops;
	    if (verbose > 1)
		printf("Checking libc malloc for correctness, ");
	    libc_stats[i].valid = eval_libc_valid(trace, i);
	    if (libc_stats[i].valid) {
		speed_params.trace = trace;
		if (verbose > 1)
		    printf("and performance.\n");
		libc_stats[i].secs = fsecs(eval_libc_speed, &speed_params);
	    }
	    free_trace(trace);
	}

	/* Display the libc results in a compact table */
	if (verbose) {
	    printf("\nResults for libc malloc:\n");
	    printresults(num_tracefiles, libc_stats);
	}
    }

    /*
     * Always run and evaluate the student's mm package
     */
    if (verbose > 1)
	printf("\nTesting mm malloc\n");

    /* Allocate the mm stats array, with one stats_t struct per tracefile */
    mm_stats = (stats_t *)calloc(num_tracefiles, sizeof(stats_t));
    if (mm_stats == NULL)
	unix_error("mm_stats calloc in main failed");
    
    /* Initialize the simulated memory system in memlib.c */
    mem_init(); 

    /* Evaluate student's mm malloc package using the K-best scheme */
    for (i=0; i < num_tracefiles; i++) {
	trace = read_trace(tracedir, tracefiles[i]);
	strncpy(mm_stats[i].trace_name, trace->trace_name, 1024);
	mm_stats[i].ops = trace->num_ops;
	if (verbose > 1)
	    printf("Checking mm_malloc for correctness, ");
	mm_stats[i].valid = eval_mm_valid(trace, i, &ranges);
	if (mm_stats[i].valid) {
	    if (verbose > 1)
		printf("efficiency, ");
	    mm_stats[i].util = eval_mm_util(trace, i, &ranges);
	    speed_params.trace = trace;
	    speed_params.ranges = ranges;
	    if (verbose > 1)
		printf("and performance.\n");
	    mm_stats[i].secs = fsecs(eval_mm_speed, &speed_params);
	}
	free_trace(trace);
    }

    /* Display the mm results in a compact table */
    if (verbose) {
	printf("\nResults for mm malloc:\n");
	printresults(num_tracefiles, mm_stats);
	printf("\n");
    }

    /* 
     * Accumulate the aggregate statistics for the student's mm package 
     */
    secs = 0;
    ops = 0;
    util = 0;
    numcorrect = 0;
    for (i=0; i < num_tracefiles; i++) {
	secs += mm_stats[i].secs;
	ops += mm_stats[i].ops;
	util += mm_stats[i].util;
	if (mm_stats[i].valid)
	    numcorrect++;
    }
    avg_mm_util = util/num_tracefiles;

    /* 
     * Compute and print the performance index 
     */
    if (errors == 0) {
	avg_mm_throughput = ops/secs;

	p1 = UTIL_WEIGHT * avg_mm_util;
	if (avg_mm_throughput > AVG_LIBC_THRUPUT) {
	    p2 = (double)(1.0 - UTIL_WEIGHT);
	} 
	else {
	    p2 = ((double) (1.0 - UTIL_WEIGHT)) * 
		(avg_mm_throughput/AVG_LIBC_THRUPUT);
	}
	
	perfindex = (p1 + p2)*100.0;
	printf("Perf index = %.0f (util) + %.0f (thru) = %.0f/100\n",
	       p1*100, 
	       p2*100, 
	       perfindex);
	
    }
    else { /* There were errors */
	perfindex = 0.0;
	printf("Terminated with %d errors\n", errors);
    }

    if (autograder) {
	printf("correct:%d\n", numcorrect);
	printf("perfidx:%.0f\n", perfindex);
    }

    exit(0);
}
Example #6
0
int main (int argc, char **argv)
{
  int ret;
  int iam;
  int rank;
  int nranks;
  int resultlen;                   /* needed by MPI_Get_processor_name() */
  char procname[MPI_MAX_PROCESSOR_NAME];
  char str[80];                    /* string to print */
  int *coreold;
  int *corenew;
  int nthreads;
  int n;
  int corechanged;                 /* logical indicates a thread changed core its running on */
  unsigned long totsleep = 0;      /* total ms slept between core changes (init to 0) */
  const unsigned long usec = 1000; /* us to sleep: 1ms */

  void whichcore (int *);
  void printresults (char *, int, int *);

  ret = MPI_Init (&argc, &argv);
  ret = MPI_Get_processor_name (procname, &resultlen);
  ret = MPI_Comm_rank (MPI_COMM_WORLD, &iam);
  ret = MPI_Comm_size (MPI_COMM_WORLD, &nranks);

  printf ("Rank %d is running on proc %s\n", iam, procname);
  nthreads = omp_get_max_threads ();
  coreold = (int *) malloc (nthreads * sizeof (int));
  corenew = (int *) malloc (nthreads * sizeof (int));
  for (n = 0; n < nthreads; ++n)
    coreold[n] = 0;

  while (1) {
#pragma omp parallel for
    for (n = 0; n < nthreads; ++n) {
      whichcore (corenew);
    }

    corechanged = 0;
    for (n = 0; n < nthreads; ++n) {
      if (corenew[n] != coreold[n]) {
	corechanged = 1;
	break;
      }
    }

    /* Loop over ranks with a barrier inside to serialize output */
    for (rank = 0; rank < nranks; ++rank) {
      if (rank == iam) {
	if (corechanged) {
	  sprintf (str, "Rank %d results changed after %lu ms", iam, totsleep);
	  printresults (str, nthreads, corenew);
	  fflush (stdout);
	  for (n = 0; n < nthreads; ++n)
	    coreold[n] = corenew[n];
	  totsleep = 0;
	}
      }
      ret = MPI_Barrier (MPI_COMM_WORLD);
    }
    usleep (usec);
    totsleep += usec / 1000;
  }
  ret = MPI_Finalize ();
}
Example #7
0
int main(int argc, char** argv, char* envp[])
{
    const char _szErrorNrandRec[]   = "<font color=\"red\">&gt;&gt;&gt; Number of patients must be between 0 and 10000</font>";

    const char _szErrorCategory[]   = "<tr><td>&nbsp;</td><td><font color=\"red\">&gt;&gt;&gt; Please enter a category to be randomised</font></td></tr>";
    const char _szErrorPercent[]    = "<tr><td>&nbsp;</td><td><font color=\"red\">&gt;&gt;&gt; Percentage must be between 0 and 100</font></td></tr>";
    const char _szErrorNrandUnrec[] = "<tr><td>&nbsp;</td><td><font color=\"red\">&gt;&gt;&gt; Number of patients must be between 0 and 10000</font></td></tr>";

    char szPercent[4]           = "\0";
    char szNrandRec[6]          = "\0";
    char szNrandUnrec[6]        = "\0";

    char szErrorCategory[100]   = "\0";
    char szErrorPercent[100]    = "\0";
    char szErrorNrandRec[100]   = "\0";
    char szErrorNrandUnrec[100] = "\0";

    int bErr = 0;

    if (USE_CGI) {
        xcgi_init(argc, argv);
        xcgi_header("html");
    }

    fprintf(stderr, "test\n");
    
    if (0 != strlen(xcgi_param_value_named("rec")))
        iFormSubmitted = FORM_REC;
    else if (0 != strlen(xcgi_param_value_named("unrec"))) 
        iFormSubmitted = FORM_UNREC;
    else
        iFormSubmitted = NONE;

    if (NONE != iFormSubmitted) {
    
        strcpy(szPercent,    xcgi_param_value_named("perc"));
        strcpy(szNrandRec,   xcgi_param_value_named("nrandrec"));
        strcpy(szNrandUnrec, xcgi_param_value_named("nrandunrec"));
        strcpy(szCategory,   xcgi_param_value_named("cat"));

        iPercent    = atoi(szPercent);
        iNrandRec   = atoi(szNrandRec);
        iNrandUnrec = atoi(szNrandUnrec);

        if (FORM_REC == iFormSubmitted) {
        
            if (0 == strlen(szNrandRec)
                || iNrandRec < 0 || iNrandRec > 100000) {
                strcpy(szErrorNrandRec, _szErrorNrandRec);
                bErr = 1;
            }
        }
        
        if (FORM_UNREC == iFormSubmitted) {
        
            if (0 == strlen(szNrandUnrec)
                || iNrandUnrec < 0 || iNrandUnrec > 100000) {
                strcpy(szErrorNrandUnrec, _szErrorNrandUnrec);
                bErr = 1;
            }

            if (0 == strlen(szPercent)
                || iPercent < 0 || iPercent > 100) {
                strcpy(szErrorPercent, _szErrorPercent);
                bErr = 1;
            }

            if (0 == strlen(szCategory)) {
                strcpy(szErrorCategory, _szErrorCategory);
                bErr = 1;
            }        
        }
        
    }
    
    if (0 == bErr  && NONE != iFormSubmitted) {

        printresults();

    } else {
    
        // introduction

        printf(
"<html>"
"<head>"
"<title>Simple Randomisation</title>"
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">"
""
"<style type=\"text/css\">"
"body   { font-family: verdana, sans-serif; font-size: 80% }"
"p,span { font-size: 80%% }"
"</style>"
""
"</head>"
""
"<body bgcolor=\"#FFFFFF\">"
"<table width=\"80%%\" align=\"center\"><tr><td>"
"<h3 align=\"center\">Allocating sufficiently large numbers of patients at random<br> "
"  to create similar treatment comparison groups</h3>"
"<p>Random allocation of patients to treatment comparison groups is one of the "
"  ways to ensure that tests of treatments are fair. It helps to create comparison "
"  groups made up of patients with comparable characteristics. Unless bias is reduced "
"  in this way, any difference in the progress of patients in the comparison groups "
"  may simply reflect the fact that they were composed of patients who were different "
"  to begin with, and that the differences were nothing to do with relative effects "
"  of the different treatments.</p>"
"<h4>Achieving balance in RECORDED patient characteristics of importance</h4>"
"<p>The larger the number of patients assigned at random to treatment comparison "
"  groups, the more likely it is that the comparison groups will be made up of "
"  patients with comparable characteristics, and the less likely that potentially "
"  important imbalances will remain. You can see this effect of increasing the "
"  numbers of patients using this randomisation program. Ask the program to randomise "
"  successively larger numbers of patients (up to 100,000) and watch the way that "
"  the characteristics of the patients in the treatment comparison groups become "
"  increasingly balanced.</p>");

    printf(
"%s\n"
"<form method=\"post\" action=\"\">"
"  <input type=\"text\" name=\"nrandrec\" value=\"%s\"size=\"6\" maxlength=\"6\">"
"  <span>Enter the number of patients to be randomised, and hit the Go button....</span>"
"  <input type=\"hidden\" name=\"rec\" value=\"rec\">"
"  <input type=\"submit\" name=\"Submit\" value=\"Go\">"
"</form>"
"<h4><br>"
"  Achieving balance in UNRECORDED patient characteristics of importance</h4>"
"<p>The program uses duration and severity of patients' health problems, and their "
"  ages, because these characteristics of patients are quite likely to influence "
"  the outcome of their illnesses, and possibly the effects of treatments as well. "
"  But what about characteristics that are important but haven't been recorded? "
"  For example, some patients may be very anxious about their illness, and this "
"  may have an impact on their progress and the effects of treatment.</p>"
"<p>Allocating sufficiently large numbers of patients at random to treatment comparison "
"  groups achieves balance in unrecorded as well as recorded characteristics of "
"  importance. To show this, replace 'very anxious' with an unrecorded characteristic "
"  of your own choice, indicate its likely frequency, and run the program by hitting "
"  Go.</p>",
    szErrorNrandRec,
    szNrandRec);

    printf(
"<form method=\"post\" action=\"\">"
"  <table border=\"0\" width=\"75%%\">"
"%s\n"
"    <tr> "
"      <td><span>Name the unrecorded characteristic here:</span></td>"
"      <td> "
"        <input type=\"text\" name=\"cat\" value=\"%s\">"
"      </td>"
"    </tr>"
"%s\n"
"    <tr> "
"      <td><span>How many people out of 100 have this characteristic?</span></td>"
"      <td>"
"        <input type=\"text\" name=\"perc\" value=\"%s\" size=\"3\" maxlength=\"3\">"
"      </td>"
"    </tr>"
"%s\n"
"    <tr>"
"      <td><span>Enter the number of patients to be randomised...</span></td>"
"      <td><input type=\"text\" name=\"nrandunrec\" value=\"%s\"size=\"6\" maxlength=\"6\"></td>"
"    </tr>"
"    <tr>"
"      <td><span>And hit Go:</span></td>"
"      <td>"
"        <input type=\"hidden\" name=\"unrec\" value=\"unrec\">"
"        <input type=\"submit\" name=\"Submit2\" value=\"Go\">"
"      </td>"
"    </tr>"
"  </table>"
"</form>"
"<p>&nbsp;</p>"
"<p>&nbsp; </p>"
"</td></tr></table>"
"</body>"
"</html>",
        szErrorCategory,
        szCategory,
        szErrorPercent,
        szPercent,
        szErrorNrandUnrec,
        szNrandUnrec);

    }

    if (USE_CGI) xcgi_exit();

    return 0;
}