Anda di halaman 1dari 2

Assignment # 2 (Due Thursday 21st October by 11:59 pm)

Submit the Assignment in GROUPS of THREE

Your job is to write programs that perform distributed array addition. Assume you have
two integer arrays A and B. You need to add these to produce a third array C:

A 8 6 3 4 6 5 1 9
+
B 3 8 7 12 11 15 20 30
=
C 11 14 10 16 17 20 21 39

Child 1 Child 2 Child 3 Child 4

Write a program which forks four children. Each child is responsible for calculating 1/4th
of the output array C as shown in the figure above. It will add its respective portion of A
and B and pass the result back to the parent. The parent will then combine all the
results in the final array C which it will display. Note that the arrays can be of any length.
You must divide it equally among the four children, whatever the length of the array.
(For simplicity you may assume that the size of the array is a multiple of 4). You program
will input the size of the array and then allocate the memory as required. (You are
provided with a starter source code which does this.)

You need to write two programs:

1) The first program will use pipes to do any inter-process communication between
the parent and its children.
2) The second program will use shared memory to communicate between the
parent and children.
Remember the following:

1) You might need more than one pipe to communicate between a parent and
multiple children.
2) Remember that the address space is duplicated at fork () so you may not need to
pass all the data through IPC. Some of it may be already available because of the
address space duplication.
3) The read and write system calls take size in terms of bytes. Be careful when
reading or writing an integer array like this. Each integer is of 4 bytes. Use the
sizeof operator whenever necessary.

You are provided with

1) An executable of the solution (named vecadd) which will show you what output
is required.
2) A source code file containing some starter code.

Deliverables for submission:

a) Source code of both programs.


b) A brief write-up of how you implemented the solutions (MAXIMUM 1 page)

Attach both files and send ONE EMAIL PER GROUP to osbee5@gmail.com. Write the
names, registration numbers and sections of each of your group members in the email.

The following tutorials may serve as helpful references:

http://faculty.kfupm.edu.sa/ics/saquib/ICS431/Lab13.pdf

http://faculty.kfupm.edu.sa/ics/saquib/ICS431/Lab14.pdf

Anda mungkin juga menyukai