int main (int argc, char **argv) { #if MPI_MASTER_WORKER int process_id; int n_processes; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &process_id); MPI_Comm_size(MPI_COMM_WORLD, &n_processes); #endif static const unsigned NO_EXTRA_MODEL[] = {}; const unsigned EXTRA_GTR[] = { model_index_GTR }; /* configuration */ pltb_config_t config; /* pltb config */ configure_attr_defaults(&config); config.extra_models = (unsigned*)&NO_EXTRA_MODEL; config.n_extra_models = 0; config.base_freq_kind = EMPIRICAL; /* pltb target */ char *datafile = NULL; /* illegal default => to be set */ /* model space config */ int upper_bound = 203; int lower_bound = 0; /* cli related configuration and variables */ opterr = 0; /* avoid errors generated by getopt */ int error = 0; int opt_index; int c; bool print_config = false; bool print_progress = false; while (1) { static struct option long_options[] = { {"data", required_argument, 0, 'f'}, {"opt-base-freq", no_argument, 0, 'b'}, {"upper-bound", required_argument, 0, 'u'}, {"lower-bound", required_argument, 0, 'l'}, {"npthreads", required_argument, 0, 'n'}, {"npthreads-tree", required_argument, 0, 's'}, {"rseed", required_argument, 0, 'r'}, {"config", no_argument, 0, 'c'}, {"progress", no_argument, 0, 'p'}, {"with-gtr", no_argument, 0, 'g'}, {0, 0, 0, 0 } }; c = getopt_long(argc, argv, "cpbgf:u:l:n:s:r:", long_options, &opt_index); if (c == -1) break; switch (c) { case 'b': config.base_freq_kind = OPTIMIZED; break; case 'f': if (access(optarg, R_OK) != -1) { datafile = optarg; } else { ERROR("Illegal dataset file: %s\n", optarg); error = 1; } break; case 'u': upper_bound = parse_int(optarg); if (upper_bound < 1 || upper_bound > 202) { ERROR("Illegal value for upper matrix index bound: %s\n", optarg); error = 1; } break; case 'l': lower_bound = parse_int(optarg); if (lower_bound < 0 || lower_bound > 202) { ERROR("Illegal value for lower matrix index bound: %s\n", optarg); error = 1; } break; case 'n': config.attr_model_eval.numberOfThreads = parse_int(optarg); if (config.attr_model_eval.numberOfThreads < 0) { ERROR("Negative value for number of pthreads: %s\n", optarg); error = 1; } break; case 's': config.attr_tree_search.numberOfThreads = parse_int(optarg); if (config.attr_tree_search.numberOfThreads < 0) { ERROR("Negative value for number of pthreads: %s\n", optarg); error = 1; } break; case 'r': config.attr_model_eval.randomNumberSeed = parse_long(optarg); config.attr_tree_search.randomNumberSeed = parse_long(optarg); break; case 'c': print_config = true; break; case 'p': print_progress = true; break; case 'g': config.n_extra_models = 1; config.extra_models = (unsigned*)&EXTRA_GTR; break; case 0: /* all long options return a value != 0 */ assert(false); break; default: error = 1; break; } } while (optind < argc) { error = 1; ERROR("Not recognized option: %s\n", argv[optind++]); break; } if (!error && !datafile) { ERROR("Missing required file argument\n"); error = 1; } if (!error) { if (lower_bound >= upper_bound) { ERROR("Upper bound greater then the lower bound.\n"); error = 1; } } if(!error) { #if MPI_MASTER_WORKER if (print_config && process_id == 0) { #else if (print_config) { #endif DBG("Configuration\n"); DBG("\tDataset: %s\n", datafile); DBG("\tRandom number seeds: %#lx/%#lx\n", config.attr_model_eval.randomNumberSeed, config.attr_tree_search.randomNumberSeed); DBG("\tBase frequencies: "); switch (config.base_freq_kind) { case EMPIRICAL: DBG("Empirical"); break; case OPTIMIZED: DBG("Optimized"); break; case EQUAL: DBG("Equal - not implemented yet"); break; } DBG("\n"); #if MPI_MASTER_WORKER DBG("\tNumber of processes: %d\n", n_processes); #endif DBG("\tNumber of threads per process: %d\n", config.attr_model_eval.numberOfThreads); DBG("\tNumber of threads for tree search: %d\n", config.attr_tree_search.numberOfThreads); #if MPI_MASTER_WORKER if (n_processes > 1) { DBG("\tImplementation: Parallel\n"); } else { DBG("\tImplementation: Sequential\n"); } #endif } // configure model space model_space_t model_space; init_range_model_space(&model_space, (unsigned)lower_bound, (unsigned)upper_bound); // choose implementation #if MPI_MASTER_WORKER if (n_processes > 1) { // mpi master worker error = run_master_worker(process_id, MPI_COMM_WORLD, datafile, &config, &model_space, print_progress); } else #endif { // sequential error = run_sequential(datafile, &config, &model_space); } if (error) { ERROR("Execution ended with error code %d\n", error); } destroy_model_space(&model_space); } else { error = 1; ERROR("Usage: %s (-f|--data) datafile [-b|--opt-freq] [(-l|--lower-bound) incl_index] [(-u|--upper-bound) excl_index] [(-n|--npthreads) number] [(-s|--npthreads-tree) number] [(-r|--rseed) longvalue] [(-c|--config)] [(-p|--progress)] [(-g|--with-gtr)]\n", argv[0]); } #if MPI_MASTER_WORKER MPI_Finalize(); #endif return error; }
int main(int argc, char **argv) { // test shell config struct stat shelltest; struct wordnode* commands; //head for list of possible paths to commands int rv = stat("shell-config", &shelltest); if (rv < 0) { printf("shell-config DNE. Please enter full path"); } else { int num_words = 0; commands = load_commands("shell-config",&num_words); //commands = "/bin/"; } char prompt[] = "prompt> "; printf("%s",prompt); fflush(stdout); int m=0; //keep track of mode char buffer[1024]; while (fgets(buffer, 1024, stdin) != NULL) { //handles comments, but only at the end of command int i=0; while (buffer[i]!='\0') { if (buffer[i]=='#') { buffer[i] = '\0'; i--; } i++; } // int size = size_of_array(buffer); char** argv = (char**) malloc(sizeof(char*)*(size+1)); make_array(buffer,argv,size); //print_array(argv,size); //printf("%d\n", size); if (m==0) { m = run_sequential(argv,size,commands); } else if (m==1) { m = run_par(argv,size); //pid_t pid; //int num; /*while ((pid = waitpid(-1, &stat, WNOHANG))>0) { printf("child process finished /n"); }*/ } printf("%s",prompt); } // end shell while loop free(argv); free_wordlist(commands); return 0; }