Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
final fix - DONE
Browse files Browse the repository at this point in the history
  • Loading branch information
sondt1337 committed Feb 26, 2024
1 parent 219918e commit b3c119c
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 37 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
.vscode
result.txt
LICENSE
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "C:/mingw64/bin/gcc.exe",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "c:/Users/ADMIN/OneDrive/Máy tính/Distributed-Computing",
"program": "c:/Users/ADMIN/OneDrive/Máy tính/Distributed-Computing/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
59 changes: 59 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
20 changes: 0 additions & 20 deletions Dockerfile

This file was deleted.

8 changes: 0 additions & 8 deletions docker-compose.yml

This file was deleted.

66 changes: 62 additions & 4 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,35 @@
import random
import json
import sys
import time

def write_total(correct_count, start_time):
with open("total.txt", "w") as file:
file.write(f"number of correct: {correct_count}\n")
file.write(f"number of incorrect: {incorrect_count}\n")
file.write(f"elapsed time: {time.time() - start_time} seconds\n")

def worker(i, F_json, G_json):
subprocess.run(["python", "worker.py", str(i), F_json, G_json])


def write_to_file(file, content):
with open(file, 'a') as f:
f.write(content + '\n')


def get_number_of_correct():
with open("total.txt", "r") as file:
lines = file.readlines()
for line in lines:
if "number of correct:" in line:
return int(line.split(":")[1].strip())

def get_number_of_incorrect():
with open("total.txt", "r") as file:
lines = file.readlines()
for line in lines:
if "number of incorrect:" in line:
return int(line.split(":")[1].strip())

def create_matrix(rows, cols):
matrix = np.random.randint(100, size=(rows, cols))
Expand Down Expand Up @@ -105,7 +125,7 @@ def recovery_threshold(m, n, p, delta_pc, Pc):

if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == "create":

start_time = time.time() # start count time
# M = 2, N = 4, P = 6, m = 2, n = 1, p = 3, Pc = 2
M, N, P, m, n, p, Pc = map(int, input("Enter M, N, P, m, n, p, Pc: ").split())
delta_pc = math.ceil(Pc / n)
Expand All @@ -128,7 +148,7 @@ def recovery_threshold(m, n, p, delta_pc, Pc):
f.write("Generated Key: " + json.dumps(key_json) + '\n')
# f.write("Program execution completed.\n")

for i in range(5): # 5 workers
for i in range(28): # 28 workers
F = calc_F(sub_matrices1, additional_matrices1, i, m, n, delta_pc)
G = calc_G(sub_matrices2, additional_matrices2, i, m, n, p, delta_pc)
FxG = np.dot(F, G)
Expand All @@ -139,6 +159,14 @@ def recovery_threshold(m, n, p, delta_pc, Pc):
r = multiprocessing.Process(target=worker, args=(i, F_json, G_json))
r.start()
r.join()
correct_count = get_number_of_correct()
incorrect_count = get_number_of_incorrect()
if correct_count >= recovery_threshold(m, n, p, delta_pc, Pc):
print("Number of correct exceeds recovery threshold. Stopping all workers.")
write_total(correct_count, start_time)
break


if len(sys.argv) == 4 and sys.argv[1] == "check":
i = int(sys.argv[2])
FmulG_json = sys.argv[3]
Expand All @@ -164,6 +192,36 @@ def recovery_threshold(m, n, p, delta_pc, Pc):
if np.array_equal(FmulG_check_str, last_line):
with open("result.txt", "a") as file:
file.write("Correct Array\n")
with open("total.txt", "r+") as total_file:
lines = total_file.readlines()
num_correct = 0
num_incorrect = 0
for line in lines:
if "number of correct:" in line:
num_correct = int(line.split(":")[1])
elif "number of incorrect:" in line:
num_incorrect = int(line.split(":")[1])

num_correct += 1
total_file.seek(0)
total_file.truncate()
total_file.write(f"number of correct: {num_correct}\n")
total_file.write(f"number of incorrect: {num_incorrect}\n")
else:
with open("result.txt", "a") as file:
file.write("Incorrect Array\n")
file.write("Incorrect Array\n")
with open("total.txt", "r+") as total_file:
lines = total_file.readlines()
num_correct = 0
num_incorrect = 0
for line in lines:
if "number of correct:" in line:
num_correct = int(line.split(":")[1])
elif "number of incorrect:" in line:
num_incorrect = int(line.split(":")[1])

num_incorrect += 1
total_file.seek(0)
total_file.truncate()
total_file.write(f"number of correct: {num_correct}\n")
total_file.write(f"number of incorrect: {num_incorrect}\n")
3 changes: 3 additions & 0 deletions total.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
number of correct: 17
number of incorrect: 1
elapsed time: 13.699374198913574 seconds
7 changes: 5 additions & 2 deletions worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
import sys
import numpy as np
import subprocess
import random

i = int(sys.argv[1])
F_json = sys.argv[2]
F = np.array(json.loads(F_json))
err = random.randint(1, 10)

G_json = sys.argv[3]
G = np.array(json.loads(G_json))

if (err == 1):
F+=F
FmulG = np.dot(F, G)
FmulG_json = json.dumps(FmulG.tolist())

def server(FmulG_json, i):
subprocess.run(["python", "server.py", "check", str(i), FmulG_json])

if __name__ == "__main__":
server(FmulG_json, i)
server(FmulG_json, i)

0 comments on commit b3c119c

Please sign in to comment.