Untitled You will code a multithreaded reader/writer system that multiplies matrices using ipc message queues. You will write two programs: package and compute. • - Package will create and populate...

C programming language assignment involving threads


Untitled You will code a multithreaded reader/writer system that multiplies matrices using ipc message queues. You will write two programs: package and compute. • -  Package will create and populate the input matrices from a pair of input files and then create a thread to package up dot product subtasks (one row * one column). Each subtask will be put on the message queue as message type 1. Once package is done creating subtask packaging threads, it will read the completed calculations from the queue and safely populate the output matrix. Once all the calculations are completed, the package will print the output matrix to the screen and the output file and exit. • -  Compute will create a pool of threads to read the subtasks from the message queue, calculate the value, complete the calculation and put the result back on the message queue with a message type 2. • Each program will capture a SIGINT. When a SIGINT is received (Ctl-C), each program will print out a status of the calculation. Ctl-\ will need to be used to terminate program. Jobs Sent 5 Jobs Received 0 • Each program will print a message when a message is successfully sent of received. Sending job id 12 type 1 size 48 (rc=0) Receiving job id 12 type 1 size 48 • Input files: one file for each input matrix with integers space delimited 34 1 2 3 4 5 6 7 8 9 10 11 12 45 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Output file: one file for the output matrix with integers space delimited 110 120 130 140 150 246 272 298 324 350 382 424 466 508 550 Format:./package

./package matrix1.dat matrix2.dat m_output.dat 3 Sending job id 0 type 1 size 48 (rc=0) Sending job id 1 type 1 size 48 (rc=0) Sending job id 2 type 1 size 48 (rc=0) Sending job id 3 type 1 size 48 (rc=0) Sending job id 4 type 1 size 48 (rc=0) ^CJobs Sent 5 Jobs Received 0 Sending job id 5 type 1 size 48 (rc=0) Sending job id 6 type 1 size 48 (rc=0) Sending job id 7 type 1 size 48 (rc=0) Sending job id 8 type 1 size 48 (rc=0) Sending job id 9 type 1 size 48 (rc=0) Sending job id 10 type 1 size 48 (rc=0) Sending job id 11 type 1 size 48 (rc=0) Sending job id 12 type 1 size 48 (rc=0) Sending job id 13 type 1 size 48 (rc=0) Receiving job id 0 type 2 size 20 Sending job id 14 type 1 size 48 (rc=0) Receiving job id 13 type 2 size 20 Receiving job id 8 type 2 size 20 Receiving job id 5 type 2 size 20 Receiving job id 4 type 2 size 20 Receiving job id 2 type 2 size 20 Receiving job id 12 type 2 size 20 ^CJobs Sent 15 Jobs Received 7 Receiving job id 10 type 2 size 20 Receiving job id 6 type 2 size 20 Receiving job id 3 type 2 size 20 Receiving job id 14 type 2 size 20 Receiving job id 1 type 2 size 20 Receiving job id 11 type 2 size 20 Receiving job id 9 type 2 size 20 Receiving job id 7 type 2 size 20 Format:./compute <-n for="" just="" read="" and="" output="" calculations=""> ./compute 3 Receiving job id 0 type 1 size 48 Sending job id 0 type 2 size 20 (rc=0) Receiving job id 1 type 1 size 48 Sending job id 1 type 2 size 20 (rc=0) Receiving job id 2 type 1 size 48 Sending job id 2 type 2 size 20 (rc=0) Receiving job id 3 type 1 size 48 Sending job id 3 type 2 size 20 (rc=0) Receiving job id 4 type 1 size 48 Sending job id 4 type 2 size 20 (rc=0) Receiving job id 5 type 1 size 48 Sending job id 5 type 2 size 20 (rc=0) Receiving job id 6 type 1 size 48 Receiving job id 7 type 1 size 48 Sending job id 6 type 2 size 20 (rc=0) Sending job id 7 type 2 size 20 (rc=0) ./compute 3 -n Receiving job id 0 type 1 size 48 Sum for cell 0,0 is 110 Receiving job id 1 type 1 size 48 Sum for cell 0,1 is 120 Receiving job id 2 type 1 size 48 Sum for cell 0,2 is 130 Receiving job id 3 type 1 size 48 Sum for cell 0,3 is 140 Receiving job id 4 type 1 size 48 Sum for cell 0,4 is 150 Receiving job id 5 type 1 size 48 Sum for cell 1,0 is 246 Receiving job id 6 type 1 size 48 Sum for cell 1,1 is 272 Receiving job id 7 type 1 size 48 Sum for cell 1,2 is 298 Receiving job id 8 type 1 size 48 Sum for cell 1,3 is 324 Receiving job id 9 type 1 size 48 Sum for cell 1,4 is 350 Receiving job id 10 type 1 size 48 Sum for cell 2,0 is 382 Receiving job id 11 type 1 size 48 Sum for cell 2,1 is 424 Receiving job id 12 type 1 size 48 Sum for cell 2,2 is 466 Receiving job id 13 type 1 size 48 Sum for cell 2,3 is 508 Receiving job id 14 type 1 size 48 Sum for cell 2,4 is 550 Message Queue Message Type: All fields, except for the message type (which must be long) should be type int. Each message struct should include: • Message type (1 for subtasks and 2 for results) • Appropriate dimension and position information for calculation • Row and column data for the calculation and/or the result typedef struct QueueMessage{ long type; int jobid; int rowvec; int colvec; int innerDim; int data[100]; 
 } Msg; • Parameters • Create one thread to package each subtask and retrieve computed sums (can be the same thread) • Assume the dimensions for the matrices are compatible but not square • No dimension will be larger than 50 numbers (you can use this to determine the largest data section possible of the queue message structure) • Minimize resource usage (do not hardcode any values other than given above) • Do not assume any ordering of the message retrieval • Maximize parallel processing • Appropriately protect data structures as needed • Minimize use of global variables (don’t use as a mechanism to avoid passing parameters) • Allocate matrix data structures on the heap • Synchronize calls to msgsnd and msgrcv • Free any allocated memory; join any threads • Do not remove IPC queue when done • Do not block on sending unless you need to (verify any failed attempts are eventually successful) • Only block on receiving if you know you have more messages coming • Only send the necessary bytes (don’t send data of 100 if the dimensions < 50)="" •="" message="" queue="" key="" should="" be="" your="" student="" id="" •="" you="" should="" use="" the="" pthreads="" library="" for="" threading.="" you="" can="" use="" mutexes="" or="" condition="" variables="" from="" the="" pthreads="" library="" and/or="" semaphores="" from="" the="" posix="" library.="" •="" appropriate="" data="" structures="" should="" be="" selected="" based="" on="" your="" knowledge="" of="" data="" structures.="" •="" algorithms="" should="" be="" efficient="" and="" appropriate.="" this="" program="" should="" demonstrate="" not="" only="" your="" understanding="" of="" process="" synchronization="" but="" your="" ability="" to="" design="" a="" program="" appropriately="" •="" no="" sleeps="" other="" than="" sleep="" between="" thread="" creation="" driven="" by="" command="" line="" argument="" •="" reading="" and="" creation="" of="" the="" input="" matrices="" (and="" associated="" thread="" creation)="" do="" not="" have="" to="" be="" in="" a="" function;="" it="" can="" be="" in="" the="" main="" function="" •="" -=""  use="" #ifdef="" debug="" to="" remove/add="" debug="" print="" statements="" based="" on="" compilation="" (-="" ddebug="0" or="" -="" ddebug="1)" •="" -=""  use="" standard="" error="" to="" print="" error="" messages="" •="" use="" assert="" to="" check="" for="" unexpected="" conditions="" •="" only="" hardcoding="" includes="" your="" student="" id="" and="" the="" data="" field="">
Nov 07, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here