int main(int argumentCount, char** arguments) { auto games = ParseInput(argumentCount, arguments); EvaluateGames(games); ReportResults(games); return 0; }
static void ProcessPacket(void *arg, QDP_PKT *pkt) { UINT64 serialno; BOOL first = TRUE; UINT16 prev; ALLPAR *par; par = (ALLPAR *) arg; ++par->count; logioMsg(par->lp, LOG_INFO, "%s(%hu, %hu) from %016llX received by application", qdpCmdString(pkt->hdr.cmd), pkt->hdr.seqno, pkt->hdr.ack, par->q330.serialno ); if (pkt->hdr.cmd == QDP_DT_DATA) { if (!first) { if (pkt->hdr.seqno != prev + 1) logioMsg(par->lp, LOG_INFO, " *** SEQNO BREAK ***"); } else { first = FALSE; } prev = pkt->hdr.seqno; } qdpProcessPacket(&par->lcq, pkt); if (par->path == NULL) ReportResults(&par->lcq); }
int WHTest_run ( int argc,char **argv ) { int i; /*double *global_sim = NULL;*/ int count_sim; int cur_point; int *check_point = NULL; double prev_p_wert = 0, own_p_wert; int *valid_pairs; /*int *global_pairs = NULL;*/ FILE *delta_file = NULL; time_t begin_time; struct timeval tv; int work_single; #ifdef PARALLEL int *displs, *rcounts; double mpi_prog_time, mpi_sim_time; #endif int start_sim, end_sim; p_wert = 0.0; /*knoten *baum;*/ #ifdef PARALLEL MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &mpi_myrank); MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); #endif /* start to count the running time */ time(&begin_time); if (argc>0) parseArg(argc, argv); /* initialize random seed based on current time */ if (isMasterProc()) { #ifndef HAVE_GETTIMEOFDAY if (random_seed < 0) { printf("WARNING: Random seed may not be well initialized since gettimeofday() is not available.\n"); printf(" You can use option -seed <NUMBER> to specify your own seed number.\n"); } #endif gettimeofday(&tv, NULL); srand((unsigned) (tv.tv_sec+tv.tv_usec)); if (random_seed < 0) random_seed = rand(); if (argc > 0) printf("Random number seed: %d\n\n", random_seed); } #ifdef PARALLEL MPI_Bcast(&random_seed, 1, MPI_INT, mpi_master_rank, MPI_COMM_WORLD); #endif start_kiss ( random_seed ); beta = 1./alpha; if (argc > 0) { ReadDataSize ( datei_name ); AllocateMemory(); } delta_sim = ( double* ) calloc ( simulation, sizeof ( double) ); valid_pairs = ( int* ) calloc ( simulation, sizeof ( int) ); if (check_times > 0) check_point = (int *) malloc(check_times * sizeof(int)); /*global_sim = ( double* ) calloc ( simulation, sizeof ( double) ); global_pairs = ( int* ) calloc ( simulation, sizeof ( int) );*/ #ifdef PARALLEL displs = (int*) malloc(mpi_size * sizeof(int)); rcounts = (int*) malloc(mpi_size * sizeof(int)); #endif if (isMasterProc() && argc > 0) printf("Input data set (%s) contains %d sequences of length %d\n", datei_name, taxa, nr_basen); if (argc > 0) ReadData ( datei_name ); if (isMasterProc()) printf("\n"); if (isMasterProc()) StartReport(); #ifdef PARALLEL mpi_prog_time = MPI_Wtime(); #endif Compute_Hij(); Compute_Qij_tij(); /*if (isMasterProc()) printf("Computing average of Q matrices\n");*/ Compute_q_hat_pairwise(); delta_data = ComputeWeissLambdaQ16(q_matrizen); if (fix_distance) FixDistance(); if (isMasterProc() && write_dist_matrix) Save_Distance(ausgabe_dist, distance); if (ml_distance) SetMLDistance(); if (isMasterProc()) printf("Computing neighbor-joining tree\n"); ComputeNeighborJoiningTree(); if (isMasterProc()) { Save_Tree ( baum + ( 2*taxa-2 ) ); printf("\nStart %d simulations\n", simulation); } #ifdef PARALLEL mpi_sim_time = MPI_Wtime(); work_single = (simulation+mpi_size-1) / mpi_size; start_sim = work_single * mpi_myrank; end_sim = work_single * (mpi_myrank+1); if (end_sim > simulation) end_sim = simulation; work_single = end_sim - start_sim; for (i = 0; i < mpi_size; i++) { displs[i] = work_single * i; rcounts[i] = work_single; if (i == mpi_size-1) rcounts[i] = simulation - displs[i]; /*if (isMasterProc()) printf(" %d ", rcounts[i]);*/ } #else work_single = simulation; start_sim = 0; end_sim = simulation; #endif for (i = 0; i < check_times; i++) { check_point[i] = work_single*(i+1) / check_times; if (i == check_times-1) check_point[i] = end_sim-start_sim; } for ( i = start_sim, count_sim = 0, own_p_wert = 0.0, cur_point = 0; i < end_sim; i++) { Simulate_Sequences_q_hat(); Compute_Hij(); Compute_Qij_tij(); delta_sim[i] = ComputeWeissLambdaQ16(q_matrizen); valid_pairs[i] = CountValidPairs(q_matrizen); count_sim++; current_sim = count_sim; if (delta_sim[i] >= delta_data) own_p_wert += 1.0; p_wert = own_p_wert / simulation; if (check_point && count_sim == check_point[cur_point]) { cur_point++; #ifdef PARALLEL MPI_Allreduce(&own_p_wert, &p_wert, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); p_wert /= simulation; MPI_Reduce(&count_sim, ¤t_sim, 1, MPI_INT, MPI_SUM, mpi_master_rank, MPI_COMM_WORLD); #endif if (isMasterProc()) { printf("%5d done", current_sim); printf(", current p-value: %5.3f\n", p_wert); if (p_wert > 0.05 && prev_p_wert <= 0.05) { printf("NOTE: Homogeneity assumption is NOT rejected (p-value > 0.05)\n"); } prev_p_wert = p_wert; } } if (p_wert > p_value_cutoff) break; } #ifdef PARALLEL /*printf("Proc %d done.\n", mpi_myrank); MPI_Barrier(MPI_COMM_WORLD);*/ if (mpi_size > 1) { MPI_Gatherv(delta_sim + start_sim, end_sim - start_sim, MPI_DOUBLE, delta_sim, rcounts, displs, MPI_DOUBLE, mpi_master_rank, MPI_COMM_WORLD); MPI_Gatherv(valid_pairs + start_sim, end_sim - start_sim, MPI_INT, valid_pairs, rcounts, displs, MPI_INT, mpi_master_rank, MPI_COMM_WORLD); for (i = 0, current_sim = 0, p_wert = 0.0; i < simulation; i++) { if (delta_sim[i] >= delta_data) p_wert += 1.0; if (delta_sim[i] != 0.0) current_sim++; } p_wert /= simulation; /* } else { MPI_Reduce(&own_p_wert, &p_wert, 1, MPI_DOUBLE, MPI_SUM, mpi_master_rank, MPI_COMM_WORLD); p_wert /= simulation; MPI_Reduce(&count_sim, ¤t_sim, 1, MPI_INT, MPI_SUM, mpi_master_rank, MPI_COMM_WORLD); }*/ } /*printf("Process %d did %d simulations\n", mpi_myrank, count_sim);*/ #endif if (isMasterProc()) { printf("%d simulations done\n", current_sim); } if (isMasterProc() && write_sim_result) { delta_file = fopen(ausgabe_sim_result, "w"); if (!delta_file) { printf ( "\nERROR: Cannot write to file %s!\n", ausgabe_sim_result ); } else { fprintf(delta_file, "Sim. Delta Valid_Qs\n"); for (i = 0, count_sim = 1; i < simulation; i++) if (delta_sim[i] != 0.0) { fprintf(delta_file, "%d\t%f\t%d\n", count_sim++, delta_sim[i], valid_pairs[i]); } fclose(delta_file); } } if (isMasterProc()) { #ifdef PARALLEL /*if (verbose_mode) { printf("Simulation time: %f\n", MPI_Wtime() - mpi_sim_time); }*/ #endif sort ( simulation, delta_sim-1); printf("\nDelta of input data: %f\n", delta_data); printf("0.95 quantile: %f\n", delta_sim[(int)floor(0.95*simulation)]); if (current_sim == simulation) printf("P-value: %f\n\n",p_wert); else printf("P-value: >%f\n\n",p_wert); if (p_wert < 0.05) { printf("RESULT: Model homogeneity is rejected (p-value cutoff 0.05)\n"); } else { printf("RESULT: Model homogeneity is NOT rejected (p-value cutoff 0.05)\n"); } ReportResults(delta_data, delta_sim[(int)floor(0.95*simulation)], p_wert); if (argc > 0) { printf("All results written to disk:\n"); printf(" WH-test report file: %s\n", ausgabe_report); if (write_sim_result) printf(" Simulation results: %s\n", ausgabe_sim_result); if (write_dist_matrix) printf(" Pairwise distances: %s\n", ausgabe_dist); } FinishReport(begin_time); #ifdef PARALLEL /*if (verbose_mode) { printf("Total time: %f\n", MPI_Wtime() - mpi_prog_time); }*/ #endif } #ifdef PARALLEL free(rcounts); free(displs); #endif if (check_point) free(check_point); free(valid_pairs); free(delta_sim); FreeMemory(); #ifdef PARALLEL MPI_Finalize(); #endif if (isMasterProc() && argc > 0) printf("Finished successfully.\n"); return 0; }