Esempio n. 1
0
main(int argc, char *argv[]) 
{
	int iproc, nproc,i, iter;
	int mask, broadcast_id;
	int dimensions, toSend;
	char host[255];

	double ain[VECSIZE], aout[VECSIZE];
	int  ind[VECSIZE];
	mpi_vector in[VECSIZE], out[VECSIZE];

	MPI_Init(&argc, &argv);
	MPI_Comm_size(MPI_COMM_WORLD, &nproc);
	MPI_Comm_rank(MPI_COMM_WORLD, &iproc);

	dimensions = ceil(log2(nproc));
	gethostname(host,253);
	//printf("I am proc %d of %d running on %s\n", iproc, nproc,host);
	// Start time here
	srand(iproc+5);
	double start = When();
	for(iter = 0; iter < ITERATIONS; iter++) {
		for(i = 0; i < VECSIZE; i++) {
			ain[i] = rand();
			// printf("init proc %d [%d]=%f\n",myrank,i,ain[i])}
		}
		for (i=0; i<VECSIZE; ++i) {
			in[i].val = ain[i];
			in[i].rank = iproc;
		}
		ReduceMax(dimensions, iproc, in, out);
		//MPI_Reduce( in, out, VECSIZE, MPI_DOUBLE_INT, MPI_MAXLOC, source, MPI_COMM_WORLD);

		// At this point, the answer resides on process root
		//if (iproc == source) {
		//	/* read ranks out */
		//	for (i=0; i<VECSIZE; ++i) {
        	//		printf("root out[%d] = %f from %d\n",i,out[i].val,out[i].rank);
		//		aout[i] = out[i].val;
		//		ind[i] = out[i].rank;
		//	}
		//}
		// Now broadcast this max vector to everyone else.
		BcastMax(dimensions, iproc, out);
		
	  	//for(i = 0; i < VECSIZE; i++) {
		//	printf("final proc %d [%d]=%f from %d\n",iproc,i,out[i].val,out[i].rank);
		//}
	}
	MPI_Finalize();
	double end = When();
	if(iproc == source) {
		printf("Time %f\n",end-start);
	}
	exit(0);
}
Esempio n. 2
0
double Statistics::MaxAbs(Image& Source, int& outX, int& outY)
{
    Check1Channel(Source);

    PrepareCoords(Source);

    Kernel(max_abs_coord, In(Source), Out(), *m_PartialResultBuffer, *m_PartialCoordBuffer, Source.Step(), Source.Width(), Source.Height());

    m_PartialResultBuffer->Read();
    m_PartialCoordBuffer->Read(true);

    return ReduceMax(m_PartialResult, m_PartialCoord, outX, outY);
}