-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADMEv1.0
More file actions
81 lines (60 loc) · 2.15 KB
/
READMEv1.0
File metadata and controls
81 lines (60 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
README for Independent Study Topic: Master Worker
SYSTEM REQUIREMENT:
GENERAL OS: UNIX/Linux (Ubuntu Preferred)
Processor: Pentium 4 (1 GHz or higher)
RAM: 512 MB
Software: Python 2.7 or higher
HOW TO RUN:
1. Save File
2. On terminal, execute command: python /dir (Change dir to to saved path
3. On prompt, input a string that is 60 char or less
4. Repeat Step 2 and 3 to test again.
DESCRIPTIONS:
1. The output prompt will display the names of all the process ID that is forked and its parent's ID. It will also display the reversed string.
1a. The script reverses the first two char of the string, the third and fourth char of the string, and so on. If the number of char is odd, the last char remains the same.
2. The script has a limitation of 60 characters (30 workers) on a 512MB memory.
3. The script forks a new process for each two char of the string. Each fork is responsible for reversing the two char assigned to them and sending them back to the master function. The master function then combines all the reversed string into a single array then prints the reversed string.
HISTORY:
-Version v0.1 Initial version using threads
-Version v0.5 First version using forks
-Version v0.5b Code comment and header
-Version v1.0 Tested for correctness and consistency.
(Number of char, time of execution, and bad inputs)
TESTING:
# of Worker | Time | Memory
2|.02|4.792kB
4|.02|4.792kB
6|.02|4.792kB
8|.02|4.792kB
10|.03|4.796kB
12|.03|4.796kB
14|.03|4.797kB
16|.03|4.797kB
18|.03|4.797kB
20|.03|4.799kB
25|.03|4.800kB
30|.04|4.802kB
import os
import math
import time
NEW TEST TO COMPARE TO PEERS:
factor = 15;
x = [[(i*10+j) for i in range(factor)] for j in range(factor)]
def worker(rev):
return sum(rev);
def master():
final=0;
for i in range(0,factor):
os.fork(); #Forks a new process
final = final + worker(x[i]);
return final;
if __name__ == "__main__":
print "Summing up Array";
print master();
15 workers: 4812 kB .03 sec
14 workers: 4808 kB .02 sec
12 workers: 4808 kb .02 sec
10 workers: 4808 kb .02 sec
6 workers: 4808 kB .02 sec
3 workers: 4804 kb .02 sec
1 worker: 4804 kb .02 sec