Assignment 1 (FIT5003)
Create threads based on user input to share the processor time.
1. The codes are written in C language compiled in a virtual machine (gcc -lpthread -o soft soft.c). 2. First, the program will give the user the option to input number of threads to be processed 1, 2..., etc using the scanf function.
3. The threads will increment using while loop.
4. After mentioning number of threads the first thread will be created for processing. The user will be asked to enter his/her student ID. 5. The user should enter the value of two integers A and B.
6. Get the modulus of student ID by 3 using if condition in order to achieve the below functionality: If the mode is equal to (0) then calculate the sum.
Else if, the mode is equal to (1) then calculate the sum of squares. Finally, if the mode is equal to (2) calculate the factorial. 7. Print the time used for each thread to process individually in seconds using (gettimeofday) function. 8. Also, the program will print the current date, month and time at the end.
Let’s assume that the use will enter 1170 as his user ID so, 1170 mod 3 which will equal to 0 it will calculate Sum of integers based on A and B entries. Then the program will ask the user to enter A: 25 and B: 50 (25+26+27…. +49) so, the total = 925. The last value is 49 based on the end value (b-1) so, 50 will not be included in the calculation.
Assumption and justification:
1. Allowing the user to enter the value of A and B is more practical than just assigning static value for A and B. 2. Specifying in if condition that input B must be greater than A, according to the condition of the end value (b-1). 3. Because of the size of the program the processor doesn’t require much time to execute and that’s the reason why the output is 0.000000 seconds.
In calculating the factorial and sum of squares if the user entered large numbers (four digits) for...
Please join StudyMode to read the full document