Esempio n. 1
0
int main()
{
	srand(time(0));

	printf("#Alg\tN\tcost\titerations\n");

	for(int i = 20; i<1000; i+=2)
	{

		// the matrix that contains the compatatibilies
		int * D = (int*) malloc( sizeof(int)*i*i );
		// the array that contains a solution
		int * a = (int*) malloc( sizeof(int)*i );
		initArray(a, -1, i);

		//initialize the matrix
		genMatrix(D, i);

		// generate a solution
		genSolution(a, i);
		
		// calculate its cost
		//printf("Initial cost: %d\n", cost(D, a, i ) );
		
		// run the algorithms
		alg1(i, D, a);
		alg2(i, D, a);

		// free() the malloc()
		free(D);
		free(a);
	}

	return 0;
}
Esempio n. 2
0
int main(int argc, char * argv[])
{
    int rank, np;
    int * D;
    int * a;
    int i;

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

    int res=-1;
    int * results;

    srand(rank + time(0));

    for(i = 20; i<100; i+=2)
    {

        // the matrix that contains the compatatibilies
        D = (int*) malloc( sizeof(int)*i*i );
        // the array that contains a solution
        a = (int*) malloc( sizeof(int)*i );

        initArray(a, -1, i);

        if(rank==0)
        {
            //initialize the matrix
            genMatrix(D, i);

            // allocate the array to receive the gold
            results = (int*) malloc( sizeof(int)*np );
        }

        // generate a solution
        genSolution(a, i);

        //send compatibily matrix and initial solution to other processes
        MPI_Bcast(D, sizeof(int)*i*i, MPI_BYTE, 0, MPI_COMM_WORLD);
        //MPI_Bcast(a, sizeof(int)*i, MPI_BYTE, 0, MPI_COMM_WORLD);

        res = alg2(i, D, a, rank);

        //MPI_Barrier(MPI_COMM_WORLD);

        MPI_Gather(&res, 1, MPI_INT, results, 1, MPI_INT, 0, MPI_COMM_WORLD);

        if(rank==0)
        {
            printf("%d\t%d\n", i, getMin(results, np) );

            // clean
            free(results);
        }

        free(D);
        free(a);

    }

    MPI_Finalize();

    return 0;
}
Esempio n. 3
0
void construct_vor() {
  S = construct_ch();
  number_points(S);
  alg2();
  clean_up();
}