Exemplo n.º 1
0
int auction_omp_search(int *pr, int *P, int (*a)[2], int nodes, int arcs, int s, int t)
{
	int result;
	int item;
	omp_lock_t pmux[Nodes];
	Queue queue = createQueue();
	int finalResult = -1;

	//#pragma omp parallel for
	for(int i = 0; i < NODES; ++i)
	{
		fpr[i] = INF;
	}

	//inicjalizacja kolejki
	for(int i = 0; i < NODES; ++i)
	{
		queue.push(&queue, i);
	}

	#pragma omp parallel do private(result, item, pr, P) shared(pmux, fpr)
	do
	{
		//dodac synchronizacje kolejki
		item = queue.pop(&queue);
		result = auction_search(pr, P, a, fpr, pmux, nodex, arcs, s, item);
			
		if (result == -2)
		{
			//wstaw na koniec kolejki gdy jest blokada
			queue.push(&queue, item);
		}
		else if (result == -1)
		{
			//usun z kolejki, usuwamy z kolejki robiac pop wiec nic tutaj nie trzeba robic
			//nothing to write
		}
		else if (result == 0)
		{
			//s==t czyli usuwam z kolejki, usuwamy z kolejki robiac pop wiec nic tutaj nie trzeba robic
			//nothing to write
		}
		else
		{
			//wstaw wynik do tablicy fpr
			fpr[item] = result;
			
			if (item == t)
			{
				finalResult = result;
				break;
			}
		}
	} while (queue.size != 0);
 
	queue.clear(&queue);

	return finalResult;
}
Exemplo n.º 2
0
int main(int argc, char* argv[])
{
	double time;
	int *prices, *P;
	int source, tail, nodes, arcs;
	int (*network)[2];
	arcs = atoi(argv[1]);
	nodes = atoi(argv[2]);
	network = (int (*)[2])malloc((arcs+nodes)*2*sizeof(int));		//przydzial pamieci dla tablicy z grafem
	read_network("outp", &source, &tail, &nodes, &arcs, network);
	prices = (int*)malloc(nodes*sizeof(int));
	P = (int*)malloc(nodes*sizeof(int));
	auction_search(prices, P, network, nodes, arcs, source, tail);
	time = clock()/CLOCKS_PER_SEC;
	printf("Czas wykonania programu: %f\n", time);
	//for(i = 0; i < nodes; i++) {
	//	printf("%d ", P[i]);
	//}
	//printf("\n");
	return 0;
}
Exemplo n.º 3
0
int main(int argc, char* argv[])
{
	double time;
	int *prices, *P;
	int i, task, source, tail, nodes, arcs;
	int (*network)[2], (*network_i)[2];
	int *a0, *a1, *ai0, *ai1, *Psse, *prsse;
	clock_t start, end;
	char *filename;

	printf("Hello\n");

	task = atoi(argv[1]);
	arcs = atoi(argv[2]);
	nodes = atoi(argv[3]);
	filename = argv[4];

	printf("P-1\n");

	network = (int (*)[2])malloc((arcs+nodes)*2*sizeof(int));		//przydzial pamieci dla tablicy z grafem
	network_i = (int (*)[2])malloc((arcs+nodes)*2*sizeof(int));
	read_network(filename, &source, &tail, &nodes, &arcs, network, network_i);

	printf("%d %d %d %d\n", network_i[0][0], network_i[0][1], network[0][0], network[0][1]);

	prices = (int*)malloc((nodes+1)*sizeof(int));
	P = (int*)malloc((nodes+1)*sizeof(int));
	printf("P0\n");

	if(task == SEQ) {
		start = clock();
		auction_search(prices, P, network, network_i, nodes, arcs, source, tail);
		end = clock();
	}
	else if(task == SSE) {
		a0 = _mm_malloc(arcs*sizeof(int), 16);
		a1 = _mm_malloc(arcs*sizeof(int), 16);
		ai0 = _mm_malloc(nodes*sizeof(int), 16);
		ai1 = _mm_malloc(nodes*sizeof(int), 16);
		Psse = _mm_malloc((nodes+1)*sizeof(int), 16);
		prsse = _mm_malloc((nodes+1)*sizeof(int), 16);
		for(i = 0; i < arcs; i++) {
			a0[i] = (int) network[i][0];
			a1[i] = (int) network[i][1];
		}
		for(i = 0; i < nodes; i++) {
			ai0[i] = (int) network_i[i][0];
			ai1[i] = (int) network_i[i][1];
		}
		for(i = 0; i <= nodes; i++) {
			Psse[i] = (int) INF;
			prsse[i] = 0;
		}
		start = clock();
		sse_auction_search(prsse, Psse, ai0, ai1, a0, a1, nodes, arcs, source, tail);	
		end = clock();
		_mm_free(a0);
		_mm_free(a1);
		_mm_free(ai0);
		_mm_free(ai1);
		_mm_free(Psse);
		_mm_free(prsse);
	}
	else {
		printf("Nieprawidlowy typ zadania\n");
		return 1;
	}
	
	time = ((double) (end - start)) / CLOCKS_PER_SEC;

	printf("Czas wykonania programu: %5.1f [ms]\n", time*1000);
	//for(i = 0; i < nodes; i++) {
	//	printf("%d ", P[i]);
	//}
	//printf("\n");
	free(network);
	free(network_i);
	free(prices);
	free(P);

	return 0;
}