forked from wncc/Hello-Foss-PyThread.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
969 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Contribution Guidelines | ||
|
||
Please note that this project is released with a **HELLO-FOSS**.<br> | ||
By participating in this project you agree to abide by its terms. | ||
|
||
Ensure your pull request adheres to the following guidelines: | ||
|
||
- Before submitting, please ensure that similar suggestions haven't already been made by searching through previous contributions. | ||
- Open source applications submitted must include an English-language README.md, a screenshot of the app in the README, and provide binaries for at least one operating system, ideally covering macOS, Linux, and Windows.- Submitted packages should be tested and documented. | ||
- Make an individual pull request for each suggestion. | ||
- Any submitted packages must be properly tested and come with clear documentation. | ||
- New categories, or improvements to the existing categorization are welcome. | ||
- Keep descriptions short and simple, but descriptive. | ||
- Start the description with a capital and end with a full stop/period. | ||
- Check your spelling and grammar. | ||
- Make sure your text editor is set to remove trailing whitespace. | ||
- The pull request should have a useful title and include a link to the package and why it should be included. | ||
|
||
By following these guidelines, you help maintain the quality and organization of the project!<br> | ||
|
||
***HAPPY LEARNING 😀😀😀*** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
5 | ||
8 | ||
4 | ||
2 | ||
1 | ||
9 | ||
10 | ||
50 | ||
80 | ||
30 | ||
33 | ||
45 | ||
65 | ||
55 | ||
21 | ||
12 | ||
38 | ||
59 | ||
23 | ||
28 | ||
43 | ||
3 | ||
6 | ||
15 | ||
18 | ||
31 | ||
39 | ||
40 | ||
90 | ||
82 | ||
70 | ||
100 | ||
58 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <malloc.h> | ||
#include <omp.h> | ||
#include <mpi.h> | ||
using namespace std; | ||
|
||
int NumberOfPoints = 0; | ||
int max_value = -1; | ||
int *p; | ||
int arr[100]; | ||
int *ReadFromFile() | ||
{ | ||
int *points; | ||
FILE *file; | ||
int index = 0; | ||
char line[10]; | ||
file = fopen("data.txt", "r"); | ||
if (file == NULL) { | ||
perror("Error opening file"); | ||
return NULL; | ||
} | ||
while (fgets(line, sizeof(line), file)) | ||
NumberOfPoints++; | ||
fclose(file); | ||
int size = NumberOfPoints; | ||
points = (int *)malloc(size* sizeof(int)); | ||
if (points == NULL) { | ||
perror("Error allocating memory"); | ||
return NULL; | ||
} | ||
|
||
file = fopen("data.txt", "r"); | ||
if (file == NULL) { | ||
perror("Error opening file"); | ||
free(points); | ||
return NULL; | ||
} | ||
while (fgets(line, sizeof(line), file)) { | ||
points[index++] = atoi(line); | ||
} | ||
fclose(file); | ||
return points; | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int indexx = 0; | ||
int *points, Bars, np, Range, tmp_Range = 0, | ||
Points_per_process; | ||
int size; | ||
int *irecv; | ||
int *AllCount, *count; | ||
int rank, NumberOfprocess, i, l, j; | ||
|
||
MPI_Init(&argc, &argv); | ||
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
MPI_Comm_size(MPI_COMM_WORLD, &NumberOfprocess); | ||
|
||
#pragma omp parallel | ||
{ | ||
np = omp_get_num_threads(); | ||
} | ||
|
||
if (rank == 0) | ||
{ | ||
cout << "Enter the number of bars" << endl; | ||
cin >> Bars; | ||
|
||
|
||
points = ReadFromFile(); | ||
Points_per_process = ((double)NumberOfPoints / (NumberOfprocess)) + 0.5; | ||
|
||
size = Points_per_process * NumberOfprocess; | ||
if (size < NumberOfPoints) | ||
size = NumberOfPoints; | ||
|
||
p = (int*)malloc(size * sizeof(int)); | ||
|
||
for (i = 0; i < size; i++) | ||
{ | ||
if (i < NumberOfPoints) | ||
p[i] = points[i]; | ||
else | ||
p[i] = -1; | ||
} | ||
Range = max_value / Bars; | ||
if (max_value % Bars != 0) | ||
{ | ||
Range++; | ||
} | ||
free(points); | ||
} | ||
|
||
MPI_Bcast(&size, 1, MPI_INT, 0, MPI_COMM_WORLD); | ||
MPI_Bcast(&Bars, 1, MPI_INT, 0, MPI_COMM_WORLD); | ||
|
||
irecv = (int*)malloc(size * sizeof(int *)); | ||
count = (int*)malloc(Bars * sizeof(int *)); | ||
|
||
MPI_Bcast(&Range, 1, MPI_INT, 0, MPI_COMM_WORLD); | ||
MPI_Bcast(&Points_per_process, 1, MPI_INT, 0, MPI_COMM_WORLD); | ||
MPI_Scatter(p, Points_per_process, MPI_INT, irecv, Points_per_process, MPI_INT, 0, MPI_COMM_WORLD); | ||
|
||
for (l = 0; l < Bars; l++) | ||
{ | ||
count[l] = 0; | ||
} | ||
|
||
#pragma omp parallel shared(AllCount) | ||
{ | ||
#pragma omp for schedule(static) | ||
for (i = 0; i < Points_per_process; i++) | ||
{ | ||
for (l = 0; l < Bars; l++) | ||
{ | ||
if (irecv[i] <= l * Range + Range && irecv[i] != -1) | ||
{ | ||
count[l]++; | ||
arr[indexx++] = l; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
free(irecv); | ||
AllCount = (int*)malloc(NumberOfPoints * sizeof(int)); | ||
MPI_Gather(arr, indexx, MPI_INT, AllCount, indexx, MPI_INT, 0, MPI_COMM_WORLD); | ||
|
||
if (rank == 0) | ||
{ | ||
// count = malloc(Bars * sizeof(int)); | ||
for (l = 0; l < Bars; l++) | ||
{ | ||
count[l] = 0; | ||
} | ||
|
||
for (i = 0; i < Bars; i++) | ||
{ | ||
for (j = 0; j < NumberOfPoints; j++) | ||
{ | ||
if (AllCount[j] == i && AllCount[j] != -1) | ||
{ | ||
count[i]++; | ||
} | ||
} | ||
} | ||
|
||
for (i = 0; i < Bars; i++) | ||
{ | ||
cout << "Bar " << i << " has " << count[i] << " points" << endl; | ||
} | ||
|
||
} | ||
MPI_Finalize(); | ||
|
||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
#include <stdbool.h> | ||
#include <omp.h> | ||
#include <iostream> | ||
#include <ostream> | ||
|
||
void l_u_d(float** a, float** l, float** u, int size) | ||
{ | ||
// Initialize a simple lock for parallel region | ||
omp_lock_t lock; | ||
omp_init_lock(&lock); | ||
|
||
// Initialize l and u matrices | ||
for (int i = 0; i < size; i++) { | ||
for (int j = 0; j < size; j++) { | ||
if (i == j) { | ||
l[i][j] = 1.0; // Diagonal elements of L are 1 | ||
u[i][j] = a[i][j]; | ||
} else if (i > j) { | ||
l[i][j] = a[i][j]; | ||
u[i][j] = 0.0; | ||
} else { | ||
l[i][j] = 0.0; | ||
u[i][j] = a[i][j]; | ||
} | ||
} | ||
} | ||
|
||
// Make the for loops of LU decomposition parallel | ||
#pragma omp parallel shared(a, l, u) | ||
{ | ||
for (int k = 0; k < size; k++) { | ||
// Update U matrix | ||
#pragma omp for schedule(static) | ||
for (int j = k; j < size; j++) { | ||
omp_set_lock(&lock); | ||
u[k][j] = a[k][j]; | ||
for (int s = 0; s < k; s++) { | ||
u[k][j] -= l[k][s] * u[s][j]; | ||
} | ||
omp_unset_lock(&lock); | ||
} | ||
|
||
// Update L matrix | ||
#pragma omp for schedule(static) | ||
for (int i = k + 1; i < size; i++) { | ||
omp_set_lock(&lock); | ||
l[i][k] = a[i][k]; | ||
for (int s = 0; s < k; s++) { | ||
l[i][k] -= l[i][s] * u[s][k]; | ||
} | ||
l[i][k] /= u[k][k]; | ||
omp_unset_lock(&lock); | ||
} | ||
} | ||
} | ||
|
||
omp_destroy_lock(&lock); | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
int size = 2; | ||
float **a, **l, **u; | ||
|
||
// Allocate memory for the 2D arrays | ||
a = (float **)malloc(size * sizeof(float *)); | ||
l = (float **)malloc(size * sizeof(float *)); | ||
u = (float **)malloc(size * sizeof(float *)); | ||
for (int i = 0; i < size; i++) { | ||
a[i] = (float *)malloc(size * sizeof(float)); | ||
l[i] = (float *)malloc(size * sizeof(float)); | ||
u[i] = (float *)malloc(size * sizeof(float)); | ||
} | ||
|
||
// Initialize the array 'a' | ||
float temp[2][2] = { | ||
{4, 3}, | ||
{6, 3} | ||
}; | ||
for (int i = 0; i < size; i++) { | ||
for (int j = 0; j < size; j++) { | ||
a[i][j] = temp[i][j]; | ||
} | ||
} | ||
l_u_d(a,l,u,size); | ||
for(int i=0;i<size;i++){ | ||
for(int j=0;j<size;j++){ | ||
printf("%f ",l[i][j]); | ||
} | ||
printf("\n"); | ||
} | ||
printf("\n"); | ||
for(int i=0;i<size;i++){ | ||
for(int j=0;j<size;j++){ | ||
printf("%f ",u[i][j]); | ||
} | ||
printf("\n"); | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.