Question
Write a simple C code to compute histograms of characters that leverage the power of multiprogramming. Your program should read a text file and print
Write a simple C code to compute histograms of characters that leverage the power of multiprogramming. Your program should read a text file and print a histogram of letters present in each line. Use your knowledge of threads and processes to parallelize it to run faster.
There are two parts to this assignment. First, you must decide whether multi-threading or multi-processing is more appropriate for this use case. Write a short report (1-page) choosing between the two and justifying your choice.
Second, you must write a C program to read a file, compute the histogram and print it per line. Your code must take in as an argument the number of threads/processes. Each thread/process must process one line and print its histogram and exit. Make sure that your code is not data-dependent i.e., each line must be processed by exactly one thread/process.
The data to test your code will be provided. An example of a histogram for a line is given below:
Input: The quick brown fox jumps over the lazy dog
Output: {'a': 1, 'b': 1, 'c': 1, 'd': 1, 'e': 3, 'f': 1, 'g': 1, 'h': 2, 'i': 1, 'j': 1, 'k': 1, 'l': 1, 'm': 1, 'n': 1, 'o': 4, 'p': 1, 'q': 1, 'r': 2, 's': 1, 't': 2, 'u': 2, 'v': 1, 'w': 1, 'x': 1, 'y': 1, 'z': 1}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started