Example #1
0
int main()
{
	double execTime = 0.0;
	double startTime, endTime;

    int k, size1, size2;

// Tell the compiler to align the a, b, and x arrays on 16-byte
// boundaries.  This allows the vectorizer to use aligned instructions
// and produce faster code.
#ifdef ALIGNED
#ifdef _WIN32
	_declspec(align(16)) FTYPE a[ROW][COLWIDTH];
    _declspec(align(16)) FTYPE b[ROW];
    _declspec(align(16)) FTYPE x[COLWIDTH];
#else
	FTYPE a[ROW][COLWIDTH]	__attribute__((aligned(16)));
	FTYPE b[ROW]			__attribute__((aligned(16)));
	FTYPE x[COLWIDTH]		__attribute__((aligned(16)));
#endif // _WIN32
#else
	FTYPE a[ROW][COLWIDTH];
	FTYPE b[ROW];
	FTYPE x[COLWIDTH];
#endif
	size1 = ROW;
	size2 = COLWIDTH;

    printf("\nROW:%d COL: %d\n",ROW,COLWIDTH);

    // initialize the arrays with data
	init_matrix(ROW,COL,1,a);
	init_array(COL,3,x);

	//start timing the matrix multiply code
	startTime = clock_it();
	for (k = 0;k < REPEATNTIMES;k++) {
#ifdef NOFUNCCALL
        int i, j;
		for (i = 0; i < size1; i++) {
			b[i] = 0;
			for (j = 0;j < size2; j++) {
				b[i] += a[i][j] * x[j];
			}
		}
#else
		matvec(size1,size2,a,b,x);
#endif
		x[0] = x[0] + 0.000001;
	}
	endTime = clock_it();
	execTime = endTime - startTime;

	printf("Execution time is %2.3f seconds\n", execTime);
	printf("GigaFlops = %f\n", (((double)REPEATNTIMES * (double)COL * (double)ROW * 2.0) / (double)(execTime))/1000000000.0);
	printsum(COL,b);

	return 0;
}
Example #2
0
static
void
test_random_throughtput()
{
    const int payload = 2000000;
    { // rand no parallel
        const double start_time = get_double_time();
        for (int kk=0; kk<payload; kk++)
        {
            rand();
        }
        const double end_time = get_double_time();

        std::cout << "rand no parallel " << static_cast<int>(1e-3*payload/(end_time-start_time)) << "krand/s " << clock_it(end_time-start_time) << std::endl;
    }

#if defined(OPENMP_FOUND)
    { // rand parallel
        const double start_time = get_double_time();
#pragma omp parallel for default(none)
        for (int kk=0; kk<payload; kk++)
        {
            rand();
        }
        const double end_time = get_double_time();

        std::cout << "rand parallel " << static_cast<int>(1e-3*payload/(end_time-start_time)) << "krand/s " << clock_it(end_time-start_time) << std::endl;
    }
#endif

    { // boost::mt no parallel
        Rng gen;
        gen.seed(rand());

        const double start_time = get_double_time();
        for (int kk=0; kk<payload; kk++)
        {
            gen();
        }
        const double end_time = get_double_time();

        std::cout << "boost::mt no parallel " << static_cast<int>(1e-3*payload/(end_time-start_time)) << "krand/s " << clock_it(end_time-start_time) << std::endl;
    }

#if defined(OPENMP_FOUND)
    { // boost::mt parallel
        Rng gen_common;
        gen_common.seed(rand());

        const double start_time = get_double_time();
        Rng gen_thread;
#pragma omp parallel default(none) shared(gen_common, std::cout) private(gen_thread)
        {
#pragma omp critical
            {
                gen_thread.seed(gen_common);
                //std::cout << "** " << gen_thread() << " " << omp_get_thread_num() << std::endl;
            }

#pragma omp for schedule(static, 10000)
            for (int kk=0; kk<payload; kk++)
            {
                gen_thread();
            }
        }
        const double end_time = get_double_time();

        std::cout << "boost::mt parallel " << static_cast<int>(1e-3*payload/(end_time-start_time)) << "krand/s " << clock_it(end_time-start_time) << std::endl;
    }
#endif

}
Game
play_game(const Options& options, Rng& rng)
{
    static const boost::regex re_url("^(?:http://)?([^/]+)(/.*)$");

    HTTPConnection connection(options.server_name);
    connection.proxy = options.proxy;
    const PTree& initial_json = connection.get_initial_state_json(options);
    //std::cout << initial_json;

    boost::match_results<std::string::const_iterator> what;
    if (!regex_search(initial_json.get<std::string>("playUrl"), what, re_url))
        throw std::runtime_error("can't parse play url");
    const std::string play_server_name(what[1].first, what[1].second);
    const std::string play_end_point(what[2].first, what[2].second);

    const std::string& view_url = initial_json.get<std::string>("viewUrl");
    std::cout << "view game at " << view_url << std::endl;
    double start_time = get_double_time();

    if (options.collect_map) { // collect maps
        const Tiles tiles = get_tiles(initial_json.get_child("game.board"));
        const HashedPair<Tiles> hashed_tiles(tiles);
        std::stringstream ss;
        ss << "map_" << std::hex << hashed_tiles.hash << std::dec << ".txt";
        std::cout << "saving " << ss.str() << std::endl;
        std::ofstream handle(ss.str().c_str());
        handle << hashed_tiles.value;
        handle.close();
    }

    Game game(initial_json);

#if defined(BOTUCT) || defined(BOTMULTI)
    Bot bot(game, options.uct_constant, options.max_mc_depth, rng);
#elif defined(BOTRANDOM)
    Bot bot(game, rng);
#else
    Bot bot(game);
#endif

#if defined(REPORTING)
    Reports reports;
#endif

    while (!game.is_finished())
    {
        OmpFlag continue_flag(true);

        std::cout << std::endl;
        std::cout << "======================================== " << clock_it(get_double_time() - start_time) << std::endl;

        game.status(std::cout);

        std::cout << "++++++++++++++++++++++++++++++++++++++++ " << clock_it(get_double_time() - start_time) << std::endl;
#if defined(REPORTING)
        Report report_aa = bot.crunch_it_baby(game, continue_flag, start_time, TURN_DURATION);
        report_aa.type = 1;
        reports.push_back(report_aa);
#else
        bot.crunch_it_baby(game, continue_flag, start_time, TURN_DURATION);
#endif

        const Direction direction = bot.get_move(game);
        std::cout << "bot direction " << direction << std::endl;

        bot.advance_game(game, direction);
        //game.status(std::cout);

        std::cout << "---------------------------------------- " << clock_it(get_double_time() - start_time) << std::endl;

        std::cout << "view game at " << view_url << std::endl;

        PTree new_json;
        double request_start_time;
        double request_end_time;
#if defined(OPENMP_FOUND)
        #pragma omp parallel sections default(shared) shared(new_json, request_end_time, request_start_time, continue_flag, play_end_point, play_server_name, start_time, bot, game)
        {

            #pragma omp section
#endif
            {
                request_start_time = get_double_time();
                new_json = connection.get_new_state_json(play_end_point, direction);
                request_end_time = get_double_time();

                continue_flag.reset();
            }

#if defined(OPENMP_FOUND)
            #pragma omp section
            {
#if defined(REPORTING)
                Report report_bb = bot.crunch_it_baby(game, continue_flag, start_time, 4);
                report_bb.type = 2;
                reports.push_back(report_bb);
#else
                bot.crunch_it_baby(game, continue_flag, start_time, 4);
#endif
            }
        }
#endif

        game.state.update(new_json);
        game.update(new_json);

        std::cout << "request took " << clock_it(request_end_time-request_start_time) << std::endl;

        //game.status(std::cout);

        std::cout << "======================================== " << clock_it(get_double_time() - start_time) << std::endl;
        start_time = get_double_time();
    }

    assert( game.is_finished() );

#if defined(REPORTING)
    save_report_file(reports, "report.txt");
#endif

    return game;
}