Question: For this assignment, you will implement a multi-threaded ASCII character count program. Your program will receive the name of an ASCII text file as a

For this assignment, you will implement a multi-threaded ASCII character count program. Your program will receive the name of an ASCII text file as a command-line argument and output the number of each kind of ASCII character in the file. In your code, set up a 64MB (67,108,864 bytes) buffer in global memory and read the contents of the file into the buffer (or as much of it as will fit). Then partition the buffer and spawn a number of threads to count the number of occurrences of each ASCII character in each partition. Use a #define preprocessor directive to specify the number of threads. Have each thread record these counts in a separate 128-element int array in global memory (stored collectively as a 2-dimensional int array). The partition bounds can be calculated in the main thread to be roughly equal in size and then passed to each worker thread using a struct. You will also need to pass a thread index to each thread so that it knows where to write its local count in the global 2-dimensional int array. Once the worker threads finish writing their local counts, they should exit. After spawning the worker threads, the main thread should wait for them all to complete. It should then add the partition counts for each ASCII character and print each overall count. For non-printable and white space ASCII characters, you should print the hexadecimal character code. Here is a sample execution:

~$ ./ASCIICount text_file

0 occurrences of 0x0

0 occurrences of 0x1

...

1032 occurrences of 0x20

5 occurrences of !

...

Your program should use the POSIX threads API including the pthread_create() and pthread_join() functions. You can use Figure 4.9 in the book and pthread demo programs from class as references. Note that you will need to link your program against the POSIX threads library by specifying -pthread on the compiler command line.

Test your program using 1, 2, 4 and 8 threads. Record the runtime for at least 5 runs of each variant counting the characters in the large.txt file from iLearn using the time command:

~$ time ./ASCIICount large.txt > /dev/null

real 0m0.106s

user 0m0.085s

sys 0m0.020s

Compute the average runtime for each variant using the wall, or real, time.

You should submit your source code and a short writeup in PDF format that includes a description of what you did and the compilation and execution output from your program. Include the compilation output for the 4 thread variant of your program. For execution output, show the output of a single run against large.txt with 4 threads. Include a chart of the average runtimes measured for 1, 2, 4, and 8 threads as well as a graph with execution time on the y axis and thread count on the x axis. Discuss the execution times as a function of the number of threads and number of cores. (Is there a change in the runtime for different thread counts? Is the change linear?) Also report the number of CPU cores on your test platform.

Here is a download link to the large text file (64mb) : https://drive.google.com/open?id=1KD2eFph8P9PfC_17KAolrLcTsxp5Z0X6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!