Question

In: Computer Science

Research a computer operation that could be improved through parallelization on a multi-core CPU. Include the...

Research a computer operation that could be improved through parallelization on a multi-core CPU. Include the following:

  • A short description of the operation (e.g., “Bitcoin mining”) in the subject of your post
  • A longer description of the computer operation
  • A description of how it could be improved through parallelization
  • Unique challenges in a parallelized version that are not present in a single-process version

Solutions

Expert Solution

Here we will see how computer multi core processor can be used for parallelisation to increase speed of Python code

In multiprocessing, parallelisation refers to the multiple cores in CPU. Today Computer processors have 2 to more cores, this can improve processing time. These cores makes possible that all calculations of section code can done parallel. Early Computers had only one CPU core or processor, which will take more execution time for all calculations of section code.

Python code allows the all section of code to run faster because it can use the advantage of multiprocessing. Python having built-in multiprocessing module that allows us to send the particular section of code to multiple cores or processors for parallel execution.

consider following subsection of python code that uses single core processor for execution. it uses for loop statement to execute the function func1.the function executed on each iteration individually. therefore it takes more CPU time to execute.

import time

def func1(x):

    if x%2 == 0:

        return 'even'

    elif x == 0:

        return 'zero'

    else:

        return 'odd'

   

starttime = time.time()

for i in range(0,15):

    y = i*i

   

    print('{} squared results in a/an {} number'.format(i, func1(y)))

   

print('That taken {} seconds'.format(time.time() - starttime))

If we use multiprocessing on multi core processor, the function func1 would be executed on multiple list items at time. therefore it takes less CPU time to execute.

The multiprocessing Python module contains Process class & Pool class. Process class sends each process to a different processor, and the Pool class sends sets of processes to different processors.

Here we will see how the above section of python code can be executed parallel on multi core processor using Process class & Pool class in multiprocessing Python module.The Process class is more efficient for small amounts of processes.Pool is useful for large amounts of processes.

Following code Uses Process class:

import time

import multiprocessing

def func1(x):

    if x%2 == 0:

        return 'even'

    elif x == 0:

        return 'zero'

    else:

        return 'odd'

def multiprocessfunc(x):

    y = x*x

    print('{} squared results in a/an {} number'.format(x, func1(y)))

   

if __name__ == '__main__':

    starttime = time.time()

    processes = []

    for i in range(0,15):

        p = multiprocessing.Process(target=multiprocessfunc, args=(i,))

        processes.append(p)

        p.start()

       

    for process in processes:

        process.join()

       

    print('That taken {} seconds'.format(time.time() - starttime))

the above python code uses the Process class, in this code the functions func1 & multiprocessfunc are executed on each list item. These functions will take a list item as one of its arguments. Next, it uses the python multiprocessing module, that creates a new process for each list item, and calls each process in one call. We making a list of these processes. once creating all the processes, get the separate output of each processor(i.e processes) and join them into a single list.

Following code Uses Pool class:

import time

import multiprocessing

def func1(x):

    if x%2 == 0:

        return 'even'

    elif x == 0:

        return 'zero'

    else:

        return 'odd'

def multiprocessfunc(x):

    y = x*x

    print('{} squared results in a/an {} number'.format(x, func1(y)))

   

if __name__ == '__main__':

   

    starttime = time.time()

    pool = multiprocessing.Pool()

    pool.map(multiprocessfunc, range(0,15))

    pool.close()

    print('That taken {} seconds'.format(time.time() - starttime))

the above code uses the Pool class, in this code the functions func1 & multiprocessfunc are executed on each list item. These functions will take a list item as one of its arguments.Next, it uses the python multiprocessing module, that creates a Pool object called pool(i.e pool = multiprocessing.Pool()).the object pool has function map.The map function takes function(i,e multiprocessfunc) that we want to process multiple times & list as arguments.


Related Solutions

Research a computer operation that could be improved through parallelization on a multi-core CPU. Include the...
Research a computer operation that could be improved through parallelization on a multi-core CPU. Include the following: A short description of the operation (e.g., “Bitcoin mining”) in the subject of your post A longer description of the computer operation A description of how it could be improved through parallelization Unique challenges in a parallelized version that are not present in a single-process version
Research the recommended core elements of a single-entity MPI and a multi-facility enterprise MPI through professional...
Research the recommended core elements of a single-entity MPI and a multi-facility enterprise MPI through professional journals and list references used.
If the AMD Ryzen 16-Core CPU saves $1,000 per computer manufactured, how would computer manufacturers’ variances...
If the AMD Ryzen 16-Core CPU saves $1,000 per computer manufactured, how would computer manufacturers’ variances be impacted? AMD is rumored to be releasing a new 16-core, 32 thread CPU, that would be significantly more powerful than its competitors – and it would be about $1,000 less expensive than the closest Intel CPU. This AMD chip is named “AMD Ryzen” and it has six more cores than Intel’s current primary desktop CPU – the Core i7 (technically, the “Core i7-6950x.)...
If the AMD Ryzen 16-Core CPU saves $1,000 per computer manufactured, how would computer manufacturers’ variances...
If the AMD Ryzen 16-Core CPU saves $1,000 per computer manufactured, how would computer manufacturers’ variances be impacted? AMD is rumored to be releasing a new 16-core, 32 thread CPU, that would be significantly more powerful than its competitors – and it would be about $1,000 less expensive than the closest Intel CPU. This AMD chip is named “AMD Ryzen” and it has six more cores than Intel’s current primary desktop CPU – the Core i7 (technically, the “Core i7-6950x.)...
Research a commercial Infra Red Thermometer. Describe the principle operation and application. Include the data sheet
Research a commercial Infra Red Thermometer. Describe the principle operation and application. Include the data sheet
Answer the following questions through research and provide the links to the source material. MANDATORY: Include...
Answer the following questions through research and provide the links to the source material. MANDATORY: Include the link(s) to the source of the answers. (paste the link(s) under each answer) MANDATORY: Include the link(s) to the source of the answers. (paste the link(s) under each answer) 1) Research and define social entrepreneurship 2) Research how organizations like Vision Spring help fight poverty 3) Research examples of social entrepreneurship other than Vision Spring Please Include the link(s) to the source of...
Suppose we need to connect Computer Network Research Lab (CNRL) network with address 167.89.0.0 through a...
Suppose we need to connect Computer Network Research Lab (CNRL) network with address 167.89.0.0 through a router to the EE Department network with address 123.0.0.0 and connect CNRL network through a router to the EE Research network with address 222.22.2.0 . Please draw a diagram for this network connection. Choose IP addresses for each interface of each router and show several hosts on each network, with their IP addresses. Please briefly explain each step.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT