Respuesta :
A program with a concurrent pipeline architecture that has three steps:
1) threads that produce 1000 random integers is given below.
What is a program?
A computer program is a series of instructions written in a programming language that can be carried out by a computer. Software is made up of both tangible and intangible components, including computer programs as one example.
Source code is the name given to a computer program that can be read by humans. Because computers can only run their native machine instructions, source code requires the assistance of another computer program to run.
As a result, the compiler of the language can convert source code into machine instructions. (An assembler is used to translate machine language programs.) An executable is the name given to the finished file. As an alternative, source code could run through the language's interpreter.
Code to produce 1000 random integers
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
//declare an array to store 1000 random integers
int a[1000];
//declare an array sum to store sums of each thread
int sum[4];
//To keep track of nth thread
int part = 0;
//function to calculate 25 array elemnts
void* sum_array(void* arg)
{
// Each thread computes sum of 1/4th of array
int thread_part = part++;
for (int i = thread_part * 25;
i < (thread_part + 1) *25; i++)
sum[thread_part] += a[i];
}
int main()
{ int i; //seeding srand(time(0));
//initialize array with 100 elements ranging in (1,1000)
for(i = 0; i < 1000; i++)
{
a[i] = rand()%1000 + 1;
}
//create threads array of size 4
pthread_t threads[4];
// Creating 4 threads
for (int i = 0; i < 4; i++)
pthread_create(&threads[i], NULL, sum_array, (void*)NULL);
// joining 4 threads i.e. waiting for all 4 threads to complete
for (int i = 0; i < 4; i++)
pthread_join(threads[i], NULL);
// adding sum of all 4 parts
int total_sum = 0;
for (int i = 0; i < 4; i++)
total_sum += sum[i];
printf("Sum of array eleements is : %d", total_sum); return 0;
}
Learn more about program
https://brainly.com/question/26134656
#SPJ4