The program has a function that takes one parameter, substitute it in a linear equation and return the value. This is done for 100000 numbers. This task is parallelized using ParallelContext(). The programming language used here is hoc.
The command used to run the program is mpiexec -n 4 nrniv -mpi squaredTESTER.hoc
Here, 4 represent the number of cores to be used to perform the task. When the number of cores are reduced, the program is executed faster.
What is the reason for this ?
The code that i ran is given below
whole_time=startsw() // start time
func f() { local s, y // a function with no context that *CHANGES*
s = $1
// a simple linear equation
// y = 0.0001*s + 0.0456
y = 0.00001*s + 0.456703
return y //except its argument
}
objref pc
pc = new ParallelContext()
pc.runworker() // mkaster returns immediately, workers in
// infinite loop running and jobs from bulletin board
first = 1
last = 100000
s = 0
if (pc.nhost == 1) { // use the serial form
for i=first, last {
s += f(i)
}
}else{ // use the bulletin board form
for i=first, last { // scatter processes
pc.submit("f", i) // any context needed by f had better be
} // the same on all hosts
while (pc.working) { // gather results
s += pc.retval // the return value for the executed function
}
}
print s
pc.done // tell workers to quit
end_time=startsw()-whole_time // startTime - endTime
print "----------------------------"
print end_time
Command to run the code : mpiexec -n 4 nrniv -mpi squaredTESTER.hoc
Alok P V is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.