given that :
#include<stdio.h>
int main() {
int a[100]; /* result vector */
int b[100], c[100]; /* vectors to be added or subtracted */
int n, i, o; /* n is vector size, i is for looping and o is for
operation performed */
/* clrscr(); use clrscr() after variable declaration to clear
console */
/* read vectors b and c */
printf("Enter number of process: \n");
scanf("%d", &n);
printf("Enter the Operation for Add enter 1 for Sub enter 2 :
\n");
scanf("%d", &o);
FILE *f = fopen("yourname.txt", "w");
printf("Enter elements of vector b:\n");
for (i = 0; i < n; i++)
scanf("%d", &b);
printf("Enter elements of vector c:\n");
for (i = 0; i < n; i++)
scanf("%d", &c);
/* perform vector addition */
for (i = 0; i < n; i++)
if(o == 1){
a = b + c;
}else if(o == 2){
a = b - c;
}else{
printf("Provided opertaion is not valid");
}
/* print addition vector a */
printf("Addition vector:\n");
for (i = 0; i < n; i++)
/* printf("%d ", a); */
fprintf(f, "%d\n", a);
/* getch(); pauses the Output Console until a key is pressed
*/
}
In this sheet you will do a task similar to the task in sheet 5 with some changes. 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] Thread0l will executes A[10:19] = B[10:19] - C [10:19] = Pl create (100/10*5=2) 2 threads → Thread10 will executes A[20:29] = B[20:29] - C [20:29] Threadll will executes A[30:39] = B[30:39] - C [30:39] = and so on. no synchronization is required
In this sheet you will do a task similar to the task in sheet 5 with some changes. Write a C code to perform vector arit
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
In this sheet you will do a task similar to the task in sheet 5 with some changes. Write a C code to perform vector arit
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!