Wednesday, November 28, 2007

Distributed calculator – Socket programing in C

Problem (Description)

Four researchers want to execute a series of calculations for their research. However, their systems have processors which are very fast for only specific calculations. For example, W’s computer executes addition fast but is slower when it comes to multiplications. These are the constraints:
1)W’s computer can only do addition fast
2)X’s computer can only do subtraction fast
3)Y’s computer can only do multiplication fast
4)Z’s computer can only do division fast

Therefore there is a need to create a distributed system that will utilize the optimized hardware in each computer and execute a series of calculations in the shortest possible time.

Each unique calculation takes 1 seconds to execute.

Rules

During the execution a process can only take care of the calculations that it specializes and must obtain help from other processes for other calculations. Simple mathematical rules of priority must be utilized to ensure correctness of calculations.

Solution

You can download the source code from here

And the problem report, where i explain every line of the code here
Part of the report is in Greek language, but you will find it easy to understand my code.

Remember

first, we run our 4 servers (server_add.c, server_sub.c, server_mul.c and server_div.c) :
gcc server_add.c -o add
./add
...
...

and then we run one by one the clients (client1.c, client2.c, client3.c and client4.c)
gcc client1.c -o c1
./c1 localhost calc.txt
...
...

2 comments:

bob said...

can i use more than 4 clients in your code?

Break Design team said...

yes you can, just make one copy of a client (e.g client1.c) and rename it as clientx.c, where x is the client number. The only thing you have to change in the code is the the id of the client