Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an MPI program, countprimes which will count the number of prime numbers i

ID: 3859398 • Letter: W

Question

Write an MPI program, countprimes which will count the number of prime numbers in the numbers from 1 to n inclusive where n is a long integer. The value for n which can be set in the program using a constant should be 50,000. Each process will test its share of the cases. Each process should print out any primes that it finds in a readable manner indicating which process found it and the actual prime. The master process should end with printing a total for the count of the number of primes and the total amount of time taken to find all the primes.

Explanation / Answer

Answer:

Assembly Language Code:

.LC0:

.string "Enter the value of N "

.LC1:

.string " "

main:

push rbp

mov rbp, rsp

sub rsp, 16

mov esi, OFFSET FLAT:.LC0

mov edi, OFFSET FLAT:std::cout

call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

lea rax, [rbp-16]

mov rsi, rax

mov edi, OFFSET FLAT:std::cin

call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)

mov DWORD PTR [rbp-4], 2

.L7:

mov eax, DWORD PTR [rbp-16]

cmp DWORD PTR [rbp-4], eax

jg .L2

mov DWORD PTR [rbp-12], 0

mov DWORD PTR [rbp-8], 2

.L5:

mov eax, DWORD PTR [rbp-4]

mov edx, eax

shr edx, 31

add eax, edx

sar eax

cmp eax, DWORD PTR [rbp-8]

jl .L3

mov eax, DWORD PTR [rbp-4]

cdq

idiv DWORD PTR [rbp-8]

mov eax, edx

test eax, eax

jne .L4

mov DWORD PTR [rbp-12], 1

jmp .L3

.L4:

add DWORD PTR [rbp-8], 1

jmp .L5

.L3:

cmp DWORD PTR [rbp-12], 0

jne .L6

mov eax, DWORD PTR [rbp-16]

cmp eax, 1

je .L6

mov eax, DWORD PTR [rbp-4]

mov esi, eax

mov edi, OFFSET FLAT:std::cout

call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

mov esi, OFFSET FLAT:.LC1

mov rdi, rax

call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

.L6:

add DWORD PTR [rbp-4], 1

jmp .L7

.L2:

mov eax, 0

leave

ret

__static_initialization_and_destruction_0(int, int):

push rbp

mov rbp, rsp

sub rsp, 16

mov DWORD PTR [rbp-4], edi

mov DWORD PTR [rbp-8], esi

cmp DWORD PTR [rbp-4], 1

jne .L11

cmp DWORD PTR [rbp-8], 65535

jne .L11

mov edi, OFFSET FLAT:std::__ioinit

call std::ios_base::Init::Init()

mov edx, OFFSET FLAT:__dso_handle

mov esi, OFFSET FLAT:std::__ioinit

mov edi, OFFSET FLAT:std::ios_base::Init::~Init()

call __cxa_atexit

.L11:

nop

leave

ret

_GLOBAL__sub_I_main:

push rbp

mov rbp, rsp

mov esi, 65535

mov edi, 1

call __static_initialization_and_destruction_0(int, int)

pop rbp

ret

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote