Esempio n. 1
0
QNetworkReply *AccelTreeResourceLoader::load(const QUrl &uri,
                                             QNetworkAccessManager *const networkManager,
                                             const ReportContext::Ptr &context, ErrorHandling errorHandling)

{
    Q_ASSERT(networkManager);
    Q_ASSERT(uri.isValid());

    NetworkLoop networkLoop;

    QNetworkRequest request(uri);
    QNetworkReply *const reply = networkManager->get(request);
    networkLoop.connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(error(QNetworkReply::NetworkError)));
    networkLoop.connect(reply, SIGNAL(finished()), SLOT(finished()));

    if(networkLoop.exec(QEventLoop::ExcludeUserInputEvents))
    {
        const QString errorMessage(escape(reply->errorString()));

        /* Note, we delete reply before we exit this function with error(). */
        delete reply;

        const QSourceLocation location(uri);

        if(context && (errorHandling == FailOnError))
            context->error(errorMessage, ReportContext::FODC0002, location);

        return 0;
    }
    else
        return reply;
}
Esempio n. 2
0
int main(int argc, char* argv[])
{
    parseArgs(argc, argv);
    b.setVerbose(verbose);

    MyDomain d(lport);
    if (host) d.addConnection(host, rport);

    l.install(&d);

    if (start) {
	if (file) {
	    char tmp[500];
	    int len = 0, c;
	    while( len<499 && (c=fgetc(file)) != EOF)
		tmp[len++] = (char) c;
	    tmp[len++]=0;

	    if (!b.setState(tmp)) {
		printf("%s: WARNING - Can not parse given position; using start position\n", argv[0]);
		b.begin(Board::color1);
	    }
	}
	else
	    b.begin(Board::color1);

	if (secsToPlay >= 0) {
	    b.setMSecsToPlay(Board::color1, 1000 * secsToPlay);
	    b.setMSecsToPlay(Board::color2, 1000 * secsToPlay);
	}
	d.sendBoard();
    }
    return l.run();
}
Esempio n. 3
0
int main(int argc, char* argv[])
{
    parseArgs(argc, argv);
    int NumTask, rank;

    MPI_Init( &argc, &argv );
    MPI_Comm_size( MPI_COMM_WORLD, &NumTask);
    MPI_Comm_rank( MPI_COMM_WORLD, &rank);

    SearchStrategy* ss = SearchStrategy::create(strategyNo);

    if (verbose)
   	printf("Using strategy '%s' ...\n", ss->name());

    ss->setMaxDepth(maxDepth);

    b.setSearchStrategy( ss );
    ss->setEvaluator(&ev);

    if( verbose )
    printf("\nIn main, rank = %d\n", rank);

    ss->registerCallbacks(new SearchCallbacks(verbose, NumTask, rank));

    // Only rank 0 opens port & communicates
    if( rank == 0 )
    {
        printf("\nStarting, rank = %d\n", rank);
        MyDomain d(lport);
        l.install(&d);
        if (host) d.addConnection(host, rport);

        //l.install(&d);
	    l.run();
    }
    else // others wait for signal from Master - rank 0
    {
    	printf("\nRank %d executing wait\n", rank);
        ss->setBoard( &b );
	    ss->wait();
    }

    MPI_Finalize();

    printf("\n Rank %d exiting from Main \n", rank );
}
Esempio n. 4
0
void MyDomain::received(char* str)
{
    if (strncmp(str, "quit", 4)==0) {
	l.exit();
	return;
    }

    if (strncmp(str, "pos ", 4)!=0) return;

    if (b.validState() != Board::empty) {

	Board newBoard;
	newBoard.setState(str+4);

	Move m = b.moveToReach(&newBoard, false);
	if (m.type == Move::none) {
	    printf("WARNING: Got a board which is not reachable via a valid move !?\n");
	    if (onlyReachable) return;
	}
	else {
	    if (b.actColor() == Board::color1)
		printf("O draws move '%s'...\n", m.name());
	    else
		printf("X draws move '%s'...\n", m.name());
	}
    }

    b.setState(str+4);
    printf(str+4);	    
    int state = b.validState();
    printf("%s\n", Board::stateDescription(state));

    switch(state) {
	case Board::timeout1:
	case Board::timeout2:
	case Board::win1:
	case Board::win2:
	    l.exit();
	default:
	    break;
    }
}
Esempio n. 5
0
int main(int argc, char* argv[])
{
    parseArgs(argc, argv);

    SearchStrategy* ss = SearchStrategy::create(strategyNo);
    if (verbose)
	printf("Using strategy '%s' ...\n", ss->name());
    ss->setMaxDepth(maxDepth);

    b.setSearchStrategy( ss );
    ss->setEvaluator(&ev);
    ss->registerCallbacks(new SearchCallbacks(verbose));

    MyDomain d(lport);
    if (host) d.addConnection(host, rport);
//    const char * host = gethostbyname("localhost");
//    d.addConnection("localhost", rport);

    l.install(&d);
    l.run();
}
Esempio n. 6
0
void MyDomain::received(char* str)
{
    static double Tottime=0;
    static long TotNoEval=0;

	//printf("\n %s", str);
    if (strncmp(str, "quit", 4)==0) {
	l.exit();
	return;
    }

    if (strncmp(str, "pos ", 4)!=0) return;

    b.setState(str+4);
    if (verbose) {
	printf("\n\n==========================================\n");
	printf(str+4);
    }

    int state = b.validState();
    if ((state != Board::valid1) && 
	(state != Board::valid2)) {
	printf("%s\n", Board::stateDescription(state));
	switch(state) {
	    case Board::timeout1:
	    case Board::timeout2:
	    case Board::win1:
	    case Board::win2:
        printf("\nTotal run time for player ");
	    printf("%s ", (myColor == Board::color1) ? "O":"X");
        printf(" =  %lf\n", (Tottime/1000));
        printf("Absolute evaluations = %ld\n ", TotNoEval);
        printf("Evaluations per sec = %lf \n", (TotNoEval*1000/Tottime));
		l.exit();
	    default:
		break;
	}
	return;
    }

    if (b.actColor() & myColor) {
	struct timeval t1, t2;

	gettimeofday(&t1,0);
	Move m = b.bestMove();
	gettimeofday(&t2,0);

	int msecsPassed =
	    (1000* t2.tv_sec + t2.tv_usec / 1000) -
	    (1000* t1.tv_sec + t1.tv_usec / 1000);

	printf("%s ", (myColor == Board::color1) ? "O":"X");
	if (m.type == Move::none) {
	    printf(" can not draw any move ?! Sorry.\n");
	    return;
	}
	printf("draws '%s' (after %d.%03d secs)...\n",
	       m.name(), msecsPassed/1000, msecsPassed%1000);
    Tottime += msecsPassed;

	b.playMove(m, msecsPassed);
	sendBoard();

	if (changeEval)
	    ev.changeEvaluation();
    
    // Sum up evaluations
    TotNoEval += ev.getNoEval();

	/* stop player at win position */
	int state = b.validState();
	if ((state != Board::valid1) && 
	    (state != Board::valid2)) {
	    printf("%s\n", Board::stateDescription(state));
	    switch(state) {
		case Board::timeout1:
		case Board::timeout2:
		case Board::win1:
		case Board::win2:
        printf("\nTotal run time for player ");
	    printf("%s ", (myColor == Board::color1) ? "O":"X");
        printf(" =  %lf\n", (Tottime/1000));
        printf("Absolute evaluations = %ld\n ", TotNoEval);
        printf("Evaluations per sec = %lf \n", (TotNoEval*1000/Tottime));
		    l.exit();
		default:
		    break;
	    }
	}

		maxMoves--;
		if (maxMoves == 0) 
		{
			//printf("\n %s", str);
		    printf("Terminating because given number of moves drawn.\n");
		    broadcast("quit\n");
		    l.exit();
		}
    }    
}
Esempio n. 7
0
int main(int argc, char* argv[])
{

	MPI_Init(&argc, &argv);

	MPI_Comm_size(MPI_COMM_WORLD, &num_threads);
	MPI_Comm_rank(MPI_COMM_WORLD, &thread_rank);

	parseArgs(argc, argv);
#if 0
        if(thread_rank < 4)
                myColor = Board::color1;
        else {
                myColor = Board::color2;
                thread_rank = thread_rank - 4;
	}
#endif
	SearchStrategy* ss = SearchStrategy::create(strategyNo);
	if (verbose)
		printf("Using strategy '%s' ...\n", ss->name());
	ss->setMaxDepth(maxDepth);

	b.setSearchStrategy( ss );
	ss->setEvaluator(&ev);
	ss->registerCallbacks(new SearchCallbacks(verbose));

	if(thread_rank == 0) {

		MyDomain d(lport);
		if (host) d.addConnection(host, rport);

		l.install(&d);
		l.run();
	}
	else
	{
		while (1)
		{
			MPI_Status mpi_st;
			Slave_Input slave_input;
			Slave_Output slave_output;
			MPI_Recv (&slave_input, sizeof(Slave_Input), MPI_BYTE, 0, 10, MPI_COMM_WORLD, &mpi_st);
			// depth= -1 is a signal for the slave to quit
			if (slave_input.depth == -1)
				break;

			ss->_board = &b;
			ss->_board->setState(slave_input.boardstate);
			ss->_board->playMove(slave_input.move);
			((ABIDStrategy*)ss)->_currentMaxDepth = slave_input.currentMaxDepth;
			ss->_sc->_leavesVisited = 0;
			ss->_sc->_nodesVisited = 0;
			/* check for a win position first */
			if (!ss->_board->isValid())
			{
				slave_output.eval = (14999-(slave_input.depth-1));
			}
			else
			{
				if ((slave_input.depth == slave_input.currentMaxDepth) && (slave_input.move.type > Move::maxPushType ))
					slave_output.eval = ss->evaluate();
				else
					slave_output.eval = -((ABIDStrategy*)ss)->alphabeta(slave_input.depth, slave_input.alpha, slave_input.beta);
			}
			((ABIDStrategy*)ss)->_pv.update(slave_input.depth-1, slave_input.move);

			slave_output.pv = ((ABIDStrategy*)ss)->_pv;
			slave_output.num_leaves = ss->_sc->_leavesVisited;
			slave_output.num_nodes = ss->_sc->_nodesVisited;
			MPI_Send(&slave_output, sizeof(Slave_Output), MPI_BYTE, 0, 10, MPI_COMM_WORLD);
		}

	}
	MPI_Finalize();

}
Esempio n. 8
0
void MyDomain::received(char* str)
{
    static double Tottime=0;
    long TotNoEval=0;

    if (strncmp(str, "quit", 4)==0) {
	l.exit();
	return;
    }

    if (strncmp(str, "pos ", 4)!=0) return;

    b.setState(str+4);
    if (verbose) {
	printf("\n\n==========================================\n");
	printf(str+4);
    }

    int state = b.validState();
    int len;
    int NumTask, i;
    MPI_Status stat;
    MPI_Comm_size( MPI_COMM_WORLD, &NumTask);

    // Sum up evaluations
    TotNoEval =  ev.getNoEval();

    if ((state != Board::valid1) && 
	(state != Board::valid2)) {
	printf("%s\n", Board::stateDescription(state));

	switch(state) 
    {
	    case Board::timeout1:
	    case Board::timeout2:
	    case Board::win1:
	    case Board::win2:
    
            char boardLayout[500];
            // Send Exit Signal to slave through EXIT board
            len = sprintf(boardLayout, "exit%s\n",b.getState());
            for( i = 1; i< NumTask; i++)
            {
                MPI_Send( boardLayout, 500, MPI_CHAR, i, 10, MPI_COMM_WORLD );
                long NoEval;
                MPI_Recv(&NoEval, 1, MPI_LONG, i, 10, MPI_COMM_WORLD, &stat);
                printf("\n Evaluations for Rank: %d Evals: %ld", i, NoEval);
                TotNoEval += NoEval;
            }

        	printf("\nTotal run time for player ");
	    	printf("%s ", (myColor == Board::color1) ? "O":"X");
        	printf(" =  %lf\n", (Tottime/1000));
	        printf("Evaluations per sec = %lf \n", (TotNoEval*1000/Tottime));
            printf("Total Evaluations= %ld\n", TotNoEval);
		    l.exit();
	    default:
		break;
	}
	return;
    }

    if (b.actColor() & myColor) {
	struct timeval t1, t2;

	gettimeofday(&t1,0);
	Move m = b.bestMove();
	gettimeofday(&t2,0);

	int msecsPassed =
	    (1000* t2.tv_sec + t2.tv_usec / 1000) -
	    (1000* t1.tv_sec + t1.tv_usec / 1000);

	printf("%s ", (myColor == Board::color1) ? "O":"X");
	if (m.type == Move::none) {
	    printf(" can not draw any move ?! Sorry.\n");
	    return;
	}
	printf("draws '%s' (after %d.%03d secs)...\n",
	       m.name(), msecsPassed/1000, msecsPassed%1000);
	    Tottime += msecsPassed;

	printf("\nMoving board for Move:%s \n ", m.name());
	b.playMove(m, msecsPassed);
	sendBoard();

	if (changeEval)
	    ev.changeEvaluation();
    
    // Sum up evaluations
    TotNoEval =  ev.getNoEval();

	/* stop player at win position */
	int state = b.validState();
	if ((state != Board::valid1) && 
	    (state != Board::valid2)) {
	    printf("%s\n", Board::stateDescription(state));
	    switch(state) {
		case Board::timeout1:
		case Board::timeout2:
		case Board::win1:
		case Board::win2:

            char boardLayout[500];
            // Send Exit Signal to slave through EXIT board
            len = sprintf(boardLayout, "exit%s\n",b.getState());
            for( i = 1; i< NumTask; i++)
            {
                MPI_Send( boardLayout, 500, MPI_CHAR, i, 10, MPI_COMM_WORLD );
                long NoEval;
                MPI_Recv(&NoEval, 1, MPI_LONG, i, 10, MPI_COMM_WORLD, &stat);
                printf("\n Evaluations for Rank: %d Evals: %ld", i, NoEval);
                TotNoEval += NoEval;
            }

	        printf("\nTotal run time for player ");
    		printf("%s ", (myColor == Board::color1) ? "O":"X");
	        printf(" =  %lf\n", (Tottime/1000));
        	printf("Evaluations per sec = %lf \n", (TotNoEval*1000/Tottime));
            printf("Total Evaluations= %ld\n", TotNoEval);
		    l.exit();
		default:
		    break;
	    }
	}

		maxMoves--;
		if (maxMoves == 0) 
		{
            char boardLayout[500];
            // Send Exit Signal to slave through EXIT board
            len = sprintf(boardLayout, "exit%s\n",b.getState());
            for( i = 1; i< NumTask; i++)
            {
                MPI_Send( boardLayout, 500, MPI_CHAR, i, 10, MPI_COMM_WORLD );
                long NoEval;
                MPI_Recv(&NoEval, 1, MPI_LONG, i, 10, MPI_COMM_WORLD, &stat);
                printf("\n Evaluations for Rank: %d Evals: %ld", i, NoEval);
                TotNoEval += NoEval;
            }

			//printf("\n %s", str);
		    printf("Terminating because given number of moves drawn.\n");
		    broadcast("quit\n");
		    l.exit();
		}
    }    
}