Write an MPI program, countprimes which will count the number of prime numbers i
ID: 3708981 • 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. Please follow the following instructions carefully before submitting your work: Before submission, make sure you clean up the directories so that no miscellaneous files are kept around in the submission. (Grade would be deducted if useless files are found in the homework directories.) Include the source code and the Makefile in the submission.Explanation / Answer
Code
.file 1 ""
.section .mdebug.abi32
.previous
.nan legacy
.module fp=32
.module nooddspreg
.abicalls
.rdata
.align 2
$LC0:
.ascii "Enter the value of num1 and num2 "
.align 2
$LC1:
.ascii "%d %d"
.align 2
$LC2:
.ascii "There are no primes upto %d "
.align 2
$LC3:
.ascii "Prime numbers are "
.align 2
$LC4:
.ascii "%d "
.align 2
$LC5:
.ascii "Number of primes between %d& %d = %d "
.text
.align 2
.globl main
.set nomips16
.set nomicromips
.ent main
.type main, @function
main:
.frame $fp,64,$31 # vars= 32, regs= 2/0, args= 16, gp= 8
.mask 0xc0000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
addiu $sp,$sp,-64
sw $31,60($sp)
sw $fp,56($sp)
move $fp,$sp
.cprestore 16
movz $31,$31,$0
sw $0,36($fp)
lw $2,%got($LC0)($28)
nop
addiu $4,$2,%lo($LC0)
lw $2,%call16(puts)($28)
nop
move $25,$2
.reloc 1f,R_MIPS_JALR,puts
1: jalr $25
nop
lw $28,16($fp)
addiu $3,$fp,48
addiu $2,$fp,44
move $6,$3
move $5,$2
lw $2,%got($LC1)($28)
nop
addiu $4,$2,%lo($LC1)
lw $2,%call16(__isoc99_scanf)($28)
nop
move $25,$2
.reloc 1f,R_MIPS_JALR,__isoc99_scanf
1: jalr $25
nop
lw $28,16($fp)
lw $2,48($fp)
nop
slt $2,$2,2
beq $2,$0,$L2
nop
lw $2,48($fp)
nop
move $5,$2
lw $2,%got($LC2)($28)
nop
addiu $4,$2,%lo($LC2)
lw $2,%call16(printf)($28)
nop
move $25,$2
.reloc 1f,R_MIPS_JALR,printf
1: jalr $25
nop
lw $28,16($fp)
move $4,$0
lw $2,%call16(exit)($28)
nop
move $25,$2
.reloc 1f,R_MIPS_JALR,exit
1: jalr $25
nop
$L2:
lw $2,%got($LC3)($28)
nop
addiu $4,$2,%lo($LC3)
lw $2,%call16(puts)($28)
nop
move $25,$2
.reloc 1f,R_MIPS_JALR,puts
1: jalr $25
nop
lw $28,16($fp)
lw $2,44($fp)
nop
sw $2,40($fp)
lw $2,44($fp)
nop
andi $2,$2,0x1
bne $2,$0,$L3
nop
lw $2,44($fp)
nop
addiu $2,$2,1
sw $2,44($fp)
$L3:
lw $2,44($fp)
nop
sw $2,24($fp)
b $L4
nop
$L10:
sw $0,32($fp)
li $2,2 # 0x2
sw $2,28($fp)
b $L5
nop
$L8:
lw $3,24($fp)
lw $2,28($fp)
nop
bne $2,$0,1f
div $0,$3,$2
break 7
1:
mfhi $2
bne $2,$0,$L6
nop
li $2,1 # 0x1
sw $2,32($fp)
b $L7
nop
$L6:
lw $2,28($fp)
nop
addiu $2,$2,1
sw $2,28($fp)
$L5:
lw $2,24($fp)
nop
srl $3,$2,31
addu $2,$3,$2
sra $2,$2,1
move $3,$2
lw $2,28($fp)
nop
slt $2,$3,$2
beq $2,$0,$L8
nop
$L7:
lw $2,32($fp)
nop
bne $2,$0,$L9
nop
lw $5,24($fp)
lw $2,%got($LC4)($28)
nop
addiu $4,$2,%lo($LC4)
lw $2,%call16(printf)($28)
nop
move $25,$2
.reloc 1f,R_MIPS_JALR,printf
1: jalr $25
nop
lw $28,16($fp)
lw $2,36($fp)
nop
addiu $2,$2,1
sw $2,36($fp)
$L9:
lw $2,24($fp)
nop
addiu $2,$2,2
sw $2,24($fp)
$L4:
lw $2,48($fp)
lw $3,24($fp)
nop
slt $2,$2,$3
beq $2,$0,$L10
nop
lw $2,48($fp)
lw $7,36($fp)
move $6,$2
lw $5,40($fp)
lw $2,%got($LC5)($28)
nop
addiu $4,$2,%lo($LC5)
lw $2,%call16(printf)($28)
nop
move $25,$2
.reloc 1f,R_MIPS_JALR,printf
1: jalr $25
nop
lw $28,16($fp)
nop
move $sp,$fp
lw $31,60($sp)
lw $fp,56($sp)
addiu $sp,$sp,64
j $31
nop
.set macro
.set reorder
.end main
.size main, .-main
.ident "GCC:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.