Пример #1
0
/**
 * @brief Read in files with arrays and join them into a single file
 * @param argc
 * @param argv[]
 * @return
 */
int main (int argc, char *argv[]) {
        AnyOption opt;

        /* parse command line options */
        opt.setFlag ("help", 'h'); /* a flag (takes no argument), supporting long and short form */
        opt.setOption ("output", 'o');
        opt.setOption ("format", 'f');
        opt.setOption ("verbose", 'v');

        opt.addUsage ("Orthonal Array Convert: convert array file into a different format");
        opt.addUsage ("Usage: oaconvert [OPTIONS] [INPUTFILE] [OUTPUTFILE]");
        opt.addUsage ("");
        opt.addUsage (" -h --help  			Prints this help ");
        opt.addUsage (" -f [FORMAT]					Output format (default: TEXT, or BINARY) ");
        opt.processCommandArgs (argc, argv);

        int verbose = opt.getIntValue ("verbose", 2);

        if (verbose > 0)
                print_copyright ();

        /* parse options */
        if (opt.getFlag ("help") || opt.getFlag ('h') || opt.getArgc () == 0) {
                opt.printUsage ();
                exit (0);
        }

        const std::string outputprefix = opt.getStringValue ('o', "");
        std::string format = opt.getStringValue ('f', "BINARY");

        arrayfile::arrayfilemode_t mode = arrayfile_t::parseModeString (format);

        if (opt.getArgc () != 2) {
                opt.printUsage ();
                exit (0);
        }

        std::string infile = opt.getArgv (0);
        std::string outfile = opt.getArgv (1);

		convert_array_file(infile, outfile, mode, verbose);

        return 0;
}
Пример #2
0
/**
 * @brief Main function for oaextendmpi and oaextendsingle
 * @param argc
 * @param argv[]
 * @return
 */
int main (int argc, char *argv[]) {
#ifdef OAEXTEND_SINGLECORE
        const int n_processors = 1;
        const int this_rank = 0;
#else
        MPI::Init (argc, argv);

        const int n_processors = MPI::COMM_WORLD.Get_size ();
        const int this_rank = MPI::COMM_WORLD.Get_rank ();
#endif

        // printf("MPI: this_rank %d\n", this_rank);

        /*----------SET STARTING ARRAY(S)-----------*/
        if (this_rank != MASTER) {
#ifdef OAEXTEND_MULTICORE
                slave_print (QUIET, "M: running core %d/%d\n", this_rank, n_processors);
#endif
                algorithm_t algorithm = MODE_INVALID;
                AnyOption *opt = parseOptions (argc, argv, algorithm);
                OAextend oaextend;
                oaextend.setAlgorithm (algorithm);

#ifdef OAEXTEND_MULTICORE
                log_print (NORMAL, "slave: receiving algorithm int\n");
                algorithm = (algorithm_t)receive_int_slave ();
                oaextend.setAlgorithm (algorithm);
// printf("slave %d: receive algorithm %d\n", this_rank, algorithm);
#endif

                extend_slave_code (this_rank, oaextend);

                delete opt;
        } else {
                double Tstart = get_time_ms ();
                int nr_extensions;
                arraylist_t solutions, extensions;

                algorithm_t algorithm = MODE_INVALID;
                AnyOption *opt = parseOptions (argc, argv, algorithm);
                print_copyright ();

                int loglevel = opt->getIntValue ('l', NORMAL);
                setloglevel (loglevel);

                int dosort = opt->getIntValue ('s', 1);
                int userowsymm = opt->getIntValue ("rowsymmetry", 1);
                int maxk = opt->getIntValue ("maxk", 100000);
                int initcolprev = opt->getIntValue ("initcolprev", 1);

                const bool streaming = opt->getFlag ("streaming");

                bool restart = false;
                if (opt->getValue ("restart") != NULL || opt->getValue ('r') != NULL) {
                        restart = true;
                }

                const char *oaconfigfile = opt->getStringValue ('c', "oaconfig.txt");
                const char *resultprefix = opt->getStringValue ('o', "result");

                arrayfile::arrayfilemode_t mode = arrayfile_t::parseModeString (opt->getStringValue ('f', "T"));

                OAextend oaextend;
                oaextend.setAlgorithm (algorithm);

                if (streaming) {
                        logstream (SYSTEM) << "operating in streaming mode, sorting of arrays will not work "
                                           << std::endl;
                        oaextend.extendarraymode = OAextend::STOREARRAY;
                }

                // J5_45
                int xx = opt->getFlag ('x');
                if (xx) {
                        oaextend.j5structure = J5_45;
                }

                if (userowsymm == 0) {
                        oaextend.use_row_symmetry = userowsymm;
                        printf ("use row symmetry -> %d\n", oaextend.use_row_symmetry);
                }
                if (opt->getFlag ('g')) {
                        std::cout << "only generating arrays (no LMC check)" << endl;
                        oaextend.checkarrays = 0;
                }

                if (opt->getFlag ("help") || (opt->getValue ("coptions") != NULL)) {
                        if (opt->getFlag ("help")) {
                                opt->printUsage ();
                        }
                        if (opt->getValue ("coptions") != NULL) {
                                print_options (cout);
                        }
                } else {
                        logstream (QUIET) << "#time start: " << currenttime () << std::endl;

                        arraydata_t *ad;
                        ad = readConfigFile (oaconfigfile);
                        ad->lmc_overflow_check ();

                        if (ad == 0) {
                                return 1;
                        }

                        log_print (NORMAL, "Using design file: %s (runs %d, strength %d)\n", oaconfigfile, ad->N,
                                   ad->strength);

                        if (oaextend.getAlgorithm () == MODE_AUTOSELECT) {
                                oaextend.setAlgorithmAuto (ad);
                        }

#ifdef OAEXTEND_SINGLECORE
                        if (initcolprev == 0) {
                                log_print (NORMAL, "setting oaextend.init_column_previous to %d\n", INITCOLUMN_ZERO);
                                oaextend.init_column_previous = INITCOLUMN_ZERO;
                        }
#endif

#ifdef OAEXTEND_MULTICORE
                        int alg = oaextend.getAlgorithm ();
                        for (int i = 0; i < n_processors; i++) {
                                if (i == MASTER) {
                                        continue;
                                }
                                log_print (NORMAL, "MASTER: sending algorithm %d to slave %d\n", alg, i);
                                send_int (alg, i);
                        }
#endif
                        colindex_t col_start;

                        log_print (SYSTEM, "using algorithm %d (%s)\n", oaextend.getAlgorithm (),
                                   oaextend.getAlgorithmName ().c_str ());
                        if (log_print (NORMAL, "")) {
                                cout << oaextend.__repr__ ();
                        }

                        if (restart) { // start from result file
                                int initres = init_restart (opt->getValue ('r'), col_start, solutions);
                                if (initres == 1) { // check if restarting went OK
                                        logstream (SYSTEM) << "Problem with restart from " << opt->getValue ('r') << ""
                                                           << endl;

#ifdef OAEXTEND_MPI
                                        MPI_Abort (MPI_COMM_WORLD, 1);
#endif
                                        exit (1);
                                }

                                if (dosort) {
                                        double Ttmp = get_time_ms ();
                                        sort (solutions.begin (), solutions.end ()); // solutions.sort();

                                        log_print (QUIET, "   sorting of initial solutions: %.3f [s]\n",
                                                   get_time_ms () - Ttmp);
                                }

                                // check that oaconfig agrees with loaded arrays
                                if (solutions.size () > 0) {
                                        if (ad->N != solutions[0].n_rows) {
                                                printf ("Problem: oaconfig does not agree with loaded arrays!\n");
                                                // free_sols(solutions); ??
                                                solutions.clear ();
                                        }
                                }

                        } else {
                                // starting with root
                                if (check_divisibility (ad) == false) { 
                                        log_print (SYSTEM, "ERROR: Failed divisibility test!\n");

#ifdef OAEXTEND_MPI
                                        MPI_Abort (MPI_COMM_WORLD, 1);
#endif
                                        exit (1);
                                }
                                create_root (ad, solutions);
                                col_start = ad->strength;
                        }

                        /*-----------MAIN EXTENSION LOOP-------------*/

                        log_print (SYSTEM, "M: running with %d procs\n", n_processors);

                        maxk = std::min (maxk, ad->ncols);

                        time_t seconds;
                        for (colindex_t current_col = col_start; current_col < maxk; current_col++) {
                                fflush (stdout);
                                arraydata_t *adcol = new arraydata_t (ad, current_col + 1);

                                if (streaming) {

                                        string fname = resultprefix;
                                        fname += "-streaming";
                                        fname += "-" + oafilestring (ad);
                                        logstream (NORMAL) << "oaextend: streaming mode: create file " << fname
                                                           << std::endl;
                                        int nb = arrayfile_t::arrayNbits (*ad);

                                        oaextend.storefile.createfile (fname, adcol->N, ad->ncols, -1, ABINARY, nb);
                                }

                                log_print (SYSTEM, "Starting with column %d (%d, total time: %.2f [s])\n",
                                           current_col + 1, (int)solutions.size (), get_time_ms () - Tstart);
                                nr_extensions = 0;
                                arraylist_t::const_iterator cur_extension;

                                int csol = 0;
                                for (cur_extension = solutions.begin (); cur_extension != solutions.end ();
                                     cur_extension++) {
                                        print_progress (csol, solutions, extensions, Tstart, current_col);
                                        logstream (NORMAL) << cur_extension[0];

                                        if (n_processors == 1) {
                                                nr_extensions += extend_array (*cur_extension, adcol,
                                                                               current_col, extensions, oaextend);
                                        } else {
#ifdef OAEXTEND_MPI
                                                throw_runtime_exception("mpi version of oextend is no longer supported");
                                                double Ttmp = get_time_ms ();
                                                int slave = collect_solutions_single (extensions, adcol);
                                                log_print (DEBUG, "   time: %.2f, collect time %.2f\n",
                                                           (get_time_ms () - Tstart), (get_time_ms () - Ttmp));

                                                /* OPTIMIZE: send multiple arrays to slave 1 once step */
                                                extend_array_mpi (cur_extension->array, 1, adcol, current_col, slave);
#endif
                                        }

#ifdef OAEXTEND_MPI
                                        if ((csol + 1) % nsolsync == 0) {
                                                collect_solutions_all (extensions, adcol);
                                        }
#endif
                                        // OPTIMIZE: periodically write part of the solutions to disk
                                        csol++; /* increase current solution */
                                }
#ifdef OAEXTEND_MPI
                                collect_solutions_all (extensions, adcol);
#endif

                                if (checkloglevel (NORMAL)) {
                                        csol = 0;
                                        for (cur_extension = extensions.begin (); cur_extension != extensions.end ();
                                             cur_extension++) {
                                                log_print (DEBUG, "%i: -----\n", ++csol);
                                                logstream (DEBUG) << cur_extension[0];
                                        }
                                }
                                if (dosort) {
                                        log_print (DEBUG, "Sorting solutions, necessary for multi-processor code\n");
                                        double Ttmp = get_time_ms ();
                                        sort (extensions.begin (), extensions.end ());
                                        log_print (DEBUG, "   sorting time: %.3f [s]\n", get_time_ms () - Ttmp);
                                }

                                save_arrays (extensions, adcol, resultprefix, mode);
                                solutions.swap (extensions); // swap old and newly found solutions
                                extensions.clear ();         // clear old to free up space for new extensions

                                log_print (SYSTEM, "Done with column %i, total of %i solutions (time %.2f s))\n",
                                           current_col + 1, (int)solutions.size (), get_time_ms () - Tstart);

                                delete adcol;

#ifdef OAANALYZE_DISCR
                                logstream (NORMAL) << "Discriminant: " << endl;
                                print_discriminant (ad->N, current_col + 1);
#endif
                        }
                        /*------------------------*/
                        time (&seconds);
                        struct tm *tminfo;
                        tminfo = localtime (&seconds);
                        log_print (SYSTEM, "TIME: %.2f s, %s", get_time_ms () - Tstart, asctime (tminfo));
                        logstream (QUIET) << "#time end: " << currenttime () << std::endl;
                        logstream (QUIET) << "#time total: " << printfstring ("%.1f", get_time_ms () - Tstart)
                                          << " [s]" << std::endl;

                        solutions.clear ();
                        delete ad;

#ifdef OAEXTEND_MPI
                        stop_slaves ();
#endif
                }

                delete opt;
        } /* end of master code */

#ifdef OAEXTEND_MPI
        MPI_Finalize ();
#endif

        return 0;
}
Пример #3
0
/**
 * @brief Filter arrays in a file and write filtered arrays to output file
 * @param argc Number of command line arguments
 * @param argv Command line arguments
 * @return
 */
int main (int argc, char *argv[]) {
        AnyOption opt;

        /* parse command line options */
        opt.setFlag ("help", 'h'); /* a flag (takes no argument), supporting long and short form */
        opt.setOption ("output", 'o');
        opt.setOption ("verbose", 'v');
        opt.setOption ("na", 'a');
        opt.setOption ("index", 'i');
        opt.setOption ("format", 'f');

        opt.addUsage ("Orthonal Array Filter: filter arrays");
        opt.addUsage ("Usage: oaanalyse [OPTIONS] [INPUTFILE] [VALUESFILE] [THRESHOLD] [OUTPUTFILE]");
        opt.addUsage ("  The VALUESFILE is a binary file with k*N double values. Here N is the number of arrays");
        opt.addUsage ("  and k the number of analysis values.");

        opt.addUsage ("");
        opt.addUsage (" -h --help  			Prints this help ");
        opt.addUsage (" -v --verbose  			Verbose level (default: 1) ");
        opt.addUsage (" -a 		 			Number of values in analysis file (default: 1) ");
        opt.addUsage (" --index 		 		Index of value to compare (default: 0) ");
        opt.addUsage (" -f [FORMAT]					Output format (default: TEXT, or BINARY; B) ");
        opt.processCommandArgs (argc, argv);

        print_copyright ();

        /* parse options */
        if (opt.getFlag ("help") || opt.getFlag ('h') || opt.getArgc () < 4) {
                opt.printUsage ();
                exit (0);
        }
        int verbose = opt.getIntValue ('v', 1);
        int na = opt.getIntValue ('a', 1);
        int index = opt.getIntValue ("index", 0);

        std::string format = opt.getStringValue ('f', "BINARY");
        arrayfile::arrayfilemode_t mode = arrayfile_t::parseModeString (format);

        /* read in the arrays */
        std::string infile = opt.getArgv (0);
        std::string anafile = opt.getArgv (1);
        double threshold = atof (opt.getArgv (2));
        std::string outfile = opt.getArgv (3);

        if (verbose)
                printf ("oafilter: input %s, threshold %f (analysisfile %d values, index %d)\n", infile.c_str (),
                        threshold, na, index);

        arraylist_t *arraylist = new arraylist_t;
        int n = readarrayfile (opt.getArgv (0), arraylist);

        if (verbose)
                printf ("oafilter: filtering %d arrays\n", n);

        // read analysis file
        FILE *afid = fopen (anafile.c_str (), "rb");
        if (afid == 0) {
                printf ("   could not read analysisfile %s\n", anafile.c_str ());
                exit (0);
        }

        double *a = new double[n * na];
        fread (a, sizeof (double), n * na, afid);
        fclose (afid);

        std::vector< int > gidx;
        ;
        for (int jj = 0; jj < n; jj++) {
                double val = a[jj * na + index];
                if (val >= threshold)
                        gidx.push_back (jj);
                if (verbose >= 2)
                        printf ("jj %d: val %f, threshold %f\n", val >= threshold, val, threshold);
        }

        // filter
        arraylist_t *filtered = new arraylist_t;
        selectArrays (*arraylist, gidx, *filtered);

        /* write arrays to file */
        if (verbose)
                cout << "Writing " << filtered->size () << " arrays (input " << arraylist->size () << ") to file "
                     << outfile << endl;
        writearrayfile (outfile.c_str (), *filtered, mode);

        /* free allocated structures */
        delete[] a;
        delete arraylist;
        delete filtered;

        return 0;
}