Write a C code to perform vector arithmetic: Define 3 vectors A[100], B[100], C[100]. Get n from as a command line argument. Example if n 10, then (./vector 10), and create n processes. (n will be one of Divisors of 100). Get operation from user: add, sub. Each process will create a number of threads. Number of threads per process = 100/(10*number of processes). Perform the operation on a chunk of the vector, for example, if n = 10, each process will create (100/10*10-1) 1 thread to add\sub 10 elements. Use execl to run the add or sub programs Parent should print A,B,C in a file. (yourname.txt) For example, n=5, operation=sub Partition work equally to each process: PO create (100/10*532) 2 threads → Thread00 will executes A[0:9] = B[0:9] - C[0:9] Thread0l will executes A[10:19] = B[10:19] - C[10:191 Pl create (100/10*5=2) 2 threads > Thread10 will executes A[20:29] = B[20:29] - C[20:29] Threadl1I will executes A[30:39] = B[30:39] - C[30:39I %3D %3D and so on. no synchronization is required For example, if the output file named (vector) the output will be like this . /vector 5 B[100]=(1,2,3,4,3,2,3,3,.etc.) C[100]=(4,2,9,4,1,2,3,3,.etc.) Enter the Operation for Add enter 1 for Sub enter 2:2 5 processes created, each process creates 2 threads. Parent process print A,B,C in. (Ahmad.txt)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 19SA
icon
Related questions
Question

Write a C code to perform vector arithmetic: Define 3 vectors A[100], B[100], C[100].

 

Get n from as a command line argument. Example if n=10, then (./vector 10), and create n processes. (n will be one of Divisors of 100).

 

Get operation from user: add, sub.

 

Each process will create a number of threads. Number of threads per process = 100/(10 number of processes). Perform the operation on a chunk of the vector, for example, if n = 10, each

 

process will create (100/10*10=1) 1 thread to add\sub 10 elements. Use execl to run the add or sub programs

 

Parent should print A.B.C in a file. (yourname.txt)

 

For example, n=5, operation sub Partition work equally to each process:

 

PO create (100/10*5=2) 2 threads →

 

Thread00 will executes A[0:9] B[0:9]-C [0:9] = Thread01 will executes A[10:19] B[10:19]-C[10:19] =

 

PI create (100/10*5=2) 2 threads →

 

Thread 10 will executes A[20:29] = B[20:29]-C [20:29] Thread11 will executes A[30:39] B[30:39]- C[30:39] =

 

and so on.

 

no synchronization is required

 

For example, if the output file named (vector) the output will be like this

 

./vector 5

 

B[100]=(1,2,3,4,3,2,3,3,......etc..)

 

C[100]=(4,2,9,4,1,2,3,3,......etc...)

 

Enter the Operation for Add enter 1 for Sub enter 2:2

 

5 processes created, each process creates 2 threads.

 

Parent process print A,B,C in. (Ahmad.txt)

Write a C code to perform vector arithmetic:
Define 3 vectors A[100], B[100], C[100].
Get n from as a command line argument. Example if n 10, then (./vector 10), and
create n processes. (n will be one of Divisors of 100).
Get operation from user: add, sub.
Each process will create a number of threads. Number of threads per process =
100/(10*number of processes).
Perform the operation on a chunk of the vector, for example, if n = 10, each
process will create (100/10*10-1) 1 thread to add\sub 10 elements.
Use execl to run the add or sub programs
Parent should print A,B,C in a file. (yourname.txt)
For example, n=5, operation=sub
Partition work equally to each process:
PO create (100/10*5=2) 2 threads →
Thread00 will executes A[0:91] = B[0:9] - C[0:9]
Thread0l will executes A[10:19] = B[10:19] - C[10:191
Pl create (100/10*5=2) 2 threads →
Thread10 will executes A[20:29] = B[20:29] - C[20:29]
ThreadlI will executes A[30:39| = B[30:39] - C[30:39]
%3D
%3D
and so on.
no synchronization is required
For example, if the output file named (vector) the output will be like this
./vector 5
B[100]=(1,2,3,4,3,2,3,3,.etc.)
C[100]=(4,2,9,4,1,2,3,3,.etc.)
Enter the Operation for Add enter 1 for Sub enter 2:2
5 processes created, each process creates 2 threads.
Parent process print A,B,C in. (Ahmad.txt)
Transcribed Image Text:Write a C code to perform vector arithmetic: Define 3 vectors A[100], B[100], C[100]. Get n from as a command line argument. Example if n 10, then (./vector 10), and create n processes. (n will be one of Divisors of 100). Get operation from user: add, sub. Each process will create a number of threads. Number of threads per process = 100/(10*number of processes). Perform the operation on a chunk of the vector, for example, if n = 10, each process will create (100/10*10-1) 1 thread to add\sub 10 elements. Use execl to run the add or sub programs Parent should print A,B,C in a file. (yourname.txt) For example, n=5, operation=sub Partition work equally to each process: PO create (100/10*5=2) 2 threads → Thread00 will executes A[0:91] = B[0:9] - C[0:9] Thread0l will executes A[10:19] = B[10:19] - C[10:191 Pl create (100/10*5=2) 2 threads → Thread10 will executes A[20:29] = B[20:29] - C[20:29] ThreadlI will executes A[30:39| = B[30:39] - C[30:39] %3D %3D and so on. no synchronization is required For example, if the output file named (vector) the output will be like this ./vector 5 B[100]=(1,2,3,4,3,2,3,3,.etc.) C[100]=(4,2,9,4,1,2,3,3,.etc.) Enter the Operation for Add enter 1 for Sub enter 2:2 5 processes created, each process creates 2 threads. Parent process print A,B,C in. (Ahmad.txt)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Race Condition
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning