Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program in dot.c which takes an integer as a command line argument and computes the following dot product: . Your program should

Write a C program in dot.c which takes an integer as a command line argument and computes the following dot product: .

Your program should utilize two threads and evenly split the work of computing the dot product between them. The output of your program should be as shown in the example program interaction provided below.

image text in transcribed

#include #include #include *This structure stores al1 of the variables that are shared between the two threads. Handle with care.* typedef struct int idx; /* index of this thread * long long *a, *b; /* vectors to dot product* int dim; dimensionality of vectors long long psum partial dot product* thread data; This is the function each thread will call to do the work of computing the partial dot product.* void' Worker(void* arg) { thread_data* dat; int idx, dim; long long a, *b; Get thread arquments* dat (thread_data) arg; idx dat->idx ; a dat-a; b dat->b; dim - dat->dim; TODO compute partial dot product and safely exit the thread... * int mainCint argc, char* argv) int dim; *Parse program arguments* if(argc != 2) { printfC"usage: ./dot "); exit(2); dim atoi(argv[1]); TODO initialize thread data structure, create threads, wait for them to terminate, add the partial sums together, then print!* Be sure not to have any memory errors/leaks!! #include #include #include *This structure stores al1 of the variables that are shared between the two threads. Handle with care.* typedef struct int idx; /* index of this thread * long long *a, *b; /* vectors to dot product* int dim; dimensionality of vectors long long psum partial dot product* thread data; This is the function each thread will call to do the work of computing the partial dot product.* void' Worker(void* arg) { thread_data* dat; int idx, dim; long long a, *b; Get thread arquments* dat (thread_data) arg; idx dat->idx ; a dat-a; b dat->b; dim - dat->dim; TODO compute partial dot product and safely exit the thread... * int mainCint argc, char* argv) int dim; *Parse program arguments* if(argc != 2) { printfC"usage: ./dot "); exit(2); dim atoi(argv[1]); TODO initialize thread data structure, create threads, wait for them to terminate, add the partial sums together, then print!* Be sure not to have any memory errors/leaks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions