Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMP 528 Multi-core and Multi-processor

Programming Assignment Report

1. cInsertion

I create three functions to solve the TSP problem, through use Distance function, I use Euclidean distance formula to compute the distance between to points. Then I use the function createDistanceMatrix to distance matrix by two for loop.

At last, I create the function named cheapestInsertion, at first, I wrote the visited list, and set all value as 0. When the function run, the first one set as 1. Use while loop to make sure that all the points in tour. Then I set the minCost as positive infinity. When the for loop worked, it will choose the cheapest distance between visited and not visited. Until the number of points in tour list matches the number of points in the tsp problem.

In main function, I use these three functions to compute the path.

This is the image of result cInsertion.c run.

2. fInsertion

like cInsertion, I create three functions to solve the TSP problem. And the function named Distance and createDistanceMatrix.

In the function farthestInsertion, the first for loop is to find the farthest point and the second for loop is to find the best insertion position.

Then through the for loop, the code can insert point in tour. And in main function we can use these three function to solve the TSP problem.

This is the result the fInsertion.c run

3. ompcInsertion

I use #pragma omp parallel for in creating the distance matrix. I think that because each iteration is independent, so use #pragma omp parallel for can make loop run in the cores parallelly. Then I use #pragma omp parallel for in the cheapestInsertion function to make sure that I can quickly find the best point.

At last I use #pragma omp critical and #pragma omp atomic to update shared variable.

As we can see, in GNU and Intel, when we use more cores to run the code, the time will be more less.

This is the result of using different Intel cores to run the code.


This is the result of using different GNU cores to run the code.

4. ompfInsertion

like ompcInsertion, I also use #pragma omp parallel for in creating distance matrix. And in farthestInsertion function, I use #pragma omp parallel for in find the farthest point.

As we can see, in GNU, more cores we use, more time we can save. And in Intel, different numbers of cores we use, the time was similar to one time.

This is the result of using GNU cores to run the code.

This is the result of using Intel cores to run the code.