Skip to content
Snippets Groups Projects
Commit 04b87174 authored by Timothy's avatar Timothy
Browse files

openMP process paralleled

parent 4deaa2fe
Branches
No related merge requests found
0 4 1 3
4 0 3 1
1 3 0 2
3 1 2 0
0 2 1 2 1
2 0 3 2 1
1 3 0 3 2
2 2 3 0 1
1 1 2 1 0
0 2 1 2 1
2 0 3 2 1
1 3 0 3 2
2 2 3 0 1
1 1 2 1 0
No preview for this file type
......@@ -74,12 +74,14 @@ void printArray(unsigned long long *arr, int V){
else if(V == 1000){
fp = fopen("../output/paralel_1000.txt", "w+");
}
else {
else if(V == 3000){
fp = fopen("../output/paralel_3000.txt", "w+");
}
else {
fp = fopen("../output/paralel_other.txt", "w+");
}
for(int i = 0; i < V*V; i++){
// printf("%d", i);
if(i % V == 0){
fprintf(fp, "\n");
// printf("\n");
......@@ -92,6 +94,16 @@ void printArray(unsigned long long *arr, int V){
fclose(fp);
}
void printArrayTerminal(unsigned long long *arr, int V){
for(int i = 0; i < V*V; i++){
if(i % V == 0){
printf("\n");
}
printf("%lld ", arr[i]);
}
printf("\n");
}
int minDistance(unsigned long long dist[], bool sptSet[], int V){
int min = INT_MAX, min_index;
......@@ -139,14 +151,27 @@ int main(int argc, char** argv) {
}
generateRandomArray(arr, num_of_node);
unsigned long long **listTempArray;
listTempArray = (unsigned long long **)malloc(num_of_node*sizeof(unsigned long long*));
for(int j=0;j<num_of_node;j++){
listTempArray[j]=(unsigned long long*)malloc(num_of_node*sizeof(unsigned long long));
}
int process_per_host;
process_per_host = num_of_node / num_of_processors;
unsigned long long* recv_data;
recv_data = (unsigned long long *)malloc(((num_of_node*process_per_host*num_of_processors)+num_of_processors)*sizeof(unsigned long long));
unsigned long long* resultArray;
resultArray = (unsigned long long *)malloc(((process_per_host*num_of_node)+1)*sizeof(unsigned long long));
// unsigned long long* resultArray;
// resultArray = (unsigned long long *)malloc(((process_per_host*num_of_node)+1)*sizeof(unsigned long long));
unsigned long long **listResultArray;
listResultArray = (unsigned long long **)malloc(num_of_processors*sizeof(unsigned long long*));
for(int j=0;j<num_of_node;j++){
listResultArray[j]=(unsigned long long*)malloc((num_of_node*process_per_host+1)*sizeof(unsigned long long));
}
#pragma omp parallel num_threads(num_of_processors)
{
......@@ -171,28 +196,28 @@ int main(int argc, char** argv) {
unsigned long long* tempArray;
tempArray = (unsigned long long *)malloc(num_of_node*sizeof(unsigned long long));
// free(tempArray);
// INSERT FLAG
// #pragma omp barrier
int count = 0;
for (int source=process_per_host*world_rank ; source < (process_per_host*world_rank + process_per_host) ; source++){
// printf("\nprocess, rank %d %d\n", process_per_host, world_rank);
dijkstra(arr, source, num_of_node, listTempArray[source]);
for(int y=0; y<num_of_node;y++){
// resultArray[(count*num_of_node) + y] = listTempArray[source][y];
listResultArray[world_rank][(count*num_of_node) + y] = listTempArray[source][y];
}
count++;
}
// resultArray[num_of_node * process_per_host] = world_rank;
// }
listResultArray[world_rank][num_of_node * process_per_host] = world_rank;
#pragma omp barrier
#pragma omp critical
{
printf("%d critical\n",world_rank);
int count = 0;
for (int source=process_per_host*world_rank ; source < (process_per_host*world_rank + process_per_host) ; source++){
// printf("\nprocess, rank %d %d\n", process_per_host, world_rank);
dijkstra(arr, source, num_of_node, tempArray);
for(int y=0; y<num_of_node;y++){
resultArray[(count*num_of_node) + y] = tempArray[y];
}
count++;
}
resultArray[num_of_node * process_per_host] = world_rank;
for(int i=0;i<process_per_host * num_of_node + 1;i++){
recv_data[world_rank*(1+process_per_host*num_of_node) +i] = resultArray[i];
// recv_data[world_rank*(1+process_per_host*num_of_node) +i] = resultArray[i];
recv_data[world_rank*(1+process_per_host*num_of_node) +i] = listResultArray[world_rank][i];
}
// Flag
......@@ -238,7 +263,7 @@ int main(int argc, char** argv) {
int sisa_source;
sisa_source = num_of_node % (process_per_host * num_of_processors);
printf("sisa : %d\n",sisa_source);
printf("\nsisa : %d\n",sisa_source);
if(num_of_node % num_of_processors != 0){
unsigned long long* tempArray;
tempArray = (unsigned long long *)malloc((num_of_node)*sizeof(unsigned long long));
......@@ -272,7 +297,7 @@ int main(int argc, char** argv) {
// if(world_rank == 0){
// printf("Time taken %f microsecond\n", dijkstra_time) * 1000000;
printArray(hasilAkhir, num_of_node);
printArrayTerminal(hasilAkhir, num_of_node);
// }
// FREE
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment