Finalized assignment

This commit is contained in:
RustyRaptor committed 2023-04-10 04:50:39 -06:00
1 parent 9c2dc6cb91
commit 56de41b434
4 files changed
+73 -69

No files matched your search

+11 -24
View File
@@ -1,27 +1,14 @@
FC = gfortran -std=gnu
SRC = gaussian_elimination.f90
EXEC = gaussian_elimination
MODULE = string_to_real.mod
MODF = string_to_real.f90
RM = rm -f
OBJMAIN = gaussian_elimination.o
OBJMOD = string_to_real.o
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
# Variables so its easy to make changes if I need to (it ended up being helpful)
all: $(EXEC)
$(EXEC): $(SRC) $(MODULE) $(OBJMOD) $(OBJMAIN)
$(FC) $(OBJMOD) $(OBJMAIN) -o $(EXEC)
$(OBJMAIN): $(SRC)
$(FC) -c $(SRC)
$(MODULE): $(MODF)
$(FC) -c $(MODF)
clean:
$(RM) $(OBJMAIN) $(OBJMOD) $(MODULE) $(EXEC)
test: clean $(EXEC)
./$(EXEC) 3 4 "matrix.txt"
all: test
test: concurrency.py
@echo "${green}For N = 4${reset}"
python3 concurrency.py 4
@echo "${green}For N = 8${reset}"
python3 concurrency.py 8
@echo "${green}For N = 16${reset}"
python3 concurrency.py 16
+6 -26
View File
@@ -1,32 +1,12 @@
## Usage
### Testing the fortran code
1. Clean, build, and run
2. (needs a file matrix.txt containing 12 reals separated by spaces)
```bash
make test
```
### Testing the code
1. Execute the code for N=4,8,16
1. `make`
3. build
```bash
make
```
4. Clean binaries
```
make clean
```
### Executing The python notebook
1. Install requirements
2. It's recommended to use a virtualenv
3. `pip install -r requirements.txt`
4. Now you can open the notebook in software that supports it.
5. You can run jupyter like this
1. `jupyter notebook`
2. alternatively you can use the full lab
1. `jupyter-lab`
6. now select `compiled_vs_interpreted.ipynb` in the browser
7. Just click "run all" its usually a double play sign.
8. The notebook also builds and executes the fortran code
### Executing The python program alone
1. `python3 concurrency.py N`
1. Where N is the size of the NxN matrix
+18 -19
View File
@@ -70,25 +70,24 @@ def main():
parser.add_argument('integer', type=int, help='An integer value')
args = parser.parse_args()
print(f"The provided integer is: {args.integer}")
print(f"The provided integer is: {args.integer}")
n = args.integer
# Task 1
matrix = generate_matrix(n)
# Task 2 (without threads)
start_time1 = time.time()
start_time1 = time.perf_counter()
max_val, min_val, avg = find_stats(matrix)
end_time1 = time.time()
end_time1 = time.perf_counter()
time_taken1 = end_time1 - start_time1
print("Without threads:")
print(f"Max: {max_val}")
print(f"Min: {min_val}")
print(f"Average: {avg}")
print(f"Time taken: {time_taken1} seconds")
print("Task 2:")
print(f"Max value: {max_val}")
print(f"Min value: {min_val}")
print(f"Average value: {avg}")
print(f"Time taken to compute max, min, and average: {time_taken1*1000} milliseconds")
# Task 3 (with threads)
start_time2 = time.time()
start_time2 = time.perf_counter()
# ThreadPoolExecutor will get the results from the threaded function
# calls and store it in results.
@@ -96,19 +95,19 @@ def main():
results = list(executor.map(
find_stats_thread, [matrix] * n, range(n)))
# Get the max, min, and avg values from the results which are a collection
# of results for each row the matrix.
# Get the max, min, and avg values from the results which are a
# collection of results for each row the matrix.
max_val = max(result[0] for result in results)
min_val = min(result[1] for result in results)
avg = sum(result[2] for result in results) / n
end_time2 = time.time()
end_time2 = time.perf_counter()
time_taken2 = end_time2 - start_time2
print("\nWith threads:")
print(f"Max: {max_val}")
print(f"Min: {min_val}")
print(f"Average: {avg}")
print(f"Time taken: {time_taken2} seconds")
print("Task 3:")
print(f"Max value: {max_val}")
print(f"Min value: {min_val}")
print(f"Average value: {avg}")
print(f"Time taken to compute max, min, and average: {time_taken2*1000} milliseconds")
if __name__ == "__main__":
main()
+38
View File
@@ -0,0 +1,38 @@
For N = 4
python3 concurrency.py 4
Task 2:
Max value: 1002791
Min value: 65525
Average value: 583485.875
Time taken to compute max, min, and average: 0.01618999522179365 milliseconds
Task 3:
Max value: 1002791
Min value: 65525
Average value: 583485.875
Time taken to compute max, min, and average: 1.744865090586245 milliseconds
For N = 8
python3 concurrency.py 8
Task 2:
Max value: 1020370
Min value: 1930
Average value: 575740.203125
Time taken to compute max, min, and average: 0.04111998714506626 milliseconds
Task 3:
Max value: 1020370
Min value: 1930
Average value: 575740.203125
Time taken to compute max, min, and average: 2.4326330749318004 milliseconds
For N = 16
python3 concurrency.py 16
Task 2:
Max value: 1045169
Min value: 515
Average value: 508425.93359375
Time taken to compute max, min, and average: 0.19333104137331247 milliseconds
Task 3:
Max value: 1045169
Min value: 515
Average value: 508425.93359375
Time taken to compute max, min, and average: 3.607164020650089 milliseconds