Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CSC461 Parallel HPC (Spring 2018) Homework 4a (60 points) Due: Monday, April 16,

ID: 3720816 • Letter: C

Question

CSC461 Parallel HPC (Spring 2018) Homework 4a (60 points) Due: Monday, April 16, 2018 by 11:59PM (via e-mail) For this assignment you are to write a Pthread program that consists of 3 threads. The first thread will sum the digits counting by 3's, the second thread will sum the digits counting by 7's and the third thread with sum the digits counting by 11's. You can use the following defines to specify the maximum value to use in the respective series: #define MAXVALUE 10000 You should max sure you value in the series is strictly less than the specified max value, e.g., for (i 0; i

Explanation / Answer

Let me know if you have any doubt.

#include<stdio.h>
#include<pthread.h>
#include<unistd.h>
#include<sys/types.h>
#define MAX_VALUE 10000
pthread_t t[3];
void *t1(void *arg)
{

int *count=(int*)arg;
int i=0;
long int sum_=0;
for(i=0;i<MAX_VALUE;i+=(*count))
{
  sum_=sum_+i;
}
printf("%ld ",sum_);
return (void *)sum_;
}
int main()
{
int sum3=3,sum7=7,sum11=11;
void *ret3,*ret7,*ret11;
long int sum=0;
long int a,b,c;
pthread_create(&t[0],NULL,t1,(void*)&sum3);
pthread_create(&t[1],NULL,t1,(void*)&sum7);
pthread_create(&t[2],NULL,t1,(void*)&sum11);

pthread_join(t[0],&ret3);
pthread_join(t[1],&ret7);
pthread_join(t[2],&ret11);

a=(long int*)ret3;
b=(long int*)ret7;
c=(long int*)ret11;
printf(" SUM3+SUM7+Sum11=%ld",a+b+c);
return 1;
}