Skip to content
Snippets Groups Projects

P2P

Open
Jammer, Timrequested to merge
p2p into main
1 file
+ 208
0
Compare changes
  • Side-by-side
  • Inline
 
#! /usr/bin/python3
 
 
from scripts.Infrastructure.ErrorGenerator import ErrorGenerator
 
from scripts.Infrastructure.Instruction import Instruction
 
 
from scripts.Infrastructure.MPICallFactory import CorrectMPICallFactory, MPICallFactory
 
from scripts.Infrastructure.TemplateFactory import get_send_recv_template, get_invalid_param_p2p_case
 
 
 
def replace_wait(wait_call, tm, wait_func_to_use):
 
assert wait_func_to_use in ["mpi_wait", "mpi_test", "mpi_waitall", "mpi_testall", "mpi_waitany", "mpi_testany",
 
"mpi_waitsome", "mpi_testsome"]
 
if wait_func_to_use == "mpi_wait":
 
return # nothing to do
 
if wait_func_to_use == "mpi_test":
 
flag_name = tm.add_stack_variable("int")
 
test_call = MPICallFactory.mpi_test(wait_call.get_arg("request"), "&" + flag_name, wait_call.get_arg("status"))
 
test_call.set_rank_executing(wait_call.get_rank_executing())
 
test_call.set_identifier(wait_call.get_identifier())
 
tm.insert_instruction(Instruction("while (!" + flag_name + "){", rank=wait_call.get_rank_executing()),
 
after_instruction=wait_call)
 
tm.insert_instruction(test_call, after_instruction=wait_call) # insertion before the improbe call
 
tm.insert_instruction(Instruction("}", rank=wait_call.get_rank_executing()), before_instruction="FREE",
 
before_first_of_list=True) # end while
 
tm.remove_instruction(wait_call)
 
return
 
if wait_func_to_use == "mpi_waitall":
 
test_call = MPICallFactory.mpi_waitall("1", wait_call.get_arg("request"), "&" + wait_call.get_arg("status"))
 
test_call.set_rank_executing(wait_call.get_rank_executing())
 
test_call.set_identifier(wait_call.get_identifier())
 
tm.insert_instruction(test_call, after_instruction=wait_call) # insertion before the improbe call
 
tm.remove_instruction(wait_call)
 
return
 
if wait_func_to_use == "mpi_testall":
 
flag_name = tm.add_stack_variable("int")
 
test_call = MPICallFactory.mpi_testall("1", wait_call.get_arg("request"), "&" + flag_name,
 
wait_call.get_arg("status"))
 
test_call.set_rank_executing(wait_call.get_rank_executing())
 
test_call.set_identifier(wait_call.get_identifier())
 
tm.insert_instruction(Instruction("while (!" + flag_name + "){", rank=wait_call.get_rank_executing()),
 
after_instruction=wait_call)
 
tm.insert_instruction(test_call, after_instruction=wait_call) # insertion before the improbe call
 
tm.insert_instruction(Instruction("}", rank=wait_call.get_rank_executing()), before_instruction="FREE",
 
before_first_of_list=True) # end while
 
tm.remove_instruction(wait_call)
 
return
 
if wait_func_to_use == "mpi_waitany":
 
idx_name = tm.add_stack_variable("int")
 
test_call = MPICallFactory.mpi_waitany("1", wait_call.get_arg("request"), "&" + idx_name,
 
"&" + wait_call.get_arg("status"))
 
test_call.set_rank_executing(wait_call.get_rank_executing())
 
test_call.set_identifier(wait_call.get_identifier())
 
tm.insert_instruction(test_call, after_instruction=wait_call) # insertion before the improbe call
 
tm.remove_instruction(wait_call)
 
return
 
if wait_func_to_use == "mpi_testany":
 
flag_name = tm.add_stack_variable("int")
 
idx_name = tm.add_stack_variable("int")
 
test_call = MPICallFactory.mpi_testany("1", wait_call.get_arg("request"), "&" + idx_name, "&" + flag_name,
 
wait_call.get_arg("status"))
 
test_call.set_rank_executing(wait_call.get_rank_executing())
 
test_call.set_identifier(wait_call.get_identifier())
 
tm.insert_instruction(Instruction("while (!" + flag_name + "){", rank=wait_call.get_rank_executing()),
 
after_instruction=wait_call)
 
tm.insert_instruction(test_call, after_instruction=wait_call) # insertion before the improbe call
 
tm.insert_instruction(Instruction("}", rank=wait_call.get_rank_executing()), before_instruction="FREE",
 
before_first_of_list=True) # end while
 
tm.remove_instruction(wait_call)
 
return
 
if wait_func_to_use == "mpi_waitsome":
 
idx_name = tm.add_stack_variable("int")
 
idx_array = tm.add_stack_variable("int")
 
test_call = MPICallFactory.mpi_waitsome("1", wait_call.get_arg("request"), "&" + idx_name,
 
"&" + idx_array, "&" + wait_call.get_arg("status"))
 
test_call.set_rank_executing(wait_call.get_rank_executing())
 
test_call.set_identifier(wait_call.get_identifier())
 
tm.insert_instruction(test_call, after_instruction=wait_call) # insertion before the improbe call
 
tm.remove_instruction(wait_call)
 
return
 
if wait_func_to_use == "mpi_testsome":
 
flag_name = tm.add_stack_variable("int")
 
idx_name = tm.add_stack_variable("int")
 
idx_array = tm.add_stack_variable("int")
 
test_call = MPICallFactory.mpi_testsome("1", wait_call.get_arg("request"), "&" + idx_name, "&" + idx_array,
 
"&" + flag_name,
 
wait_call.get_arg("status"))
 
test_call.set_rank_executing(wait_call.get_rank_executing())
 
test_call.set_identifier(wait_call.get_identifier())
 
tm.insert_instruction(Instruction("while (!" + flag_name + "){", rank=wait_call.get_rank_executing()),
 
after_instruction=wait_call)
 
tm.insert_instruction(test_call, after_instruction=wait_call) # insertion before the improbe call
 
tm.insert_instruction(Instruction("}", rank=wait_call.get_rank_executing()), before_instruction="FREE",
 
before_first_of_list=True) # end while
 
tm.remove_instruction(wait_call)
 
return
 
assert False and "Not implemented"
 
 
 
class InvalidStatusErrorP2P(ErrorGenerator):
 
# statusES ignore is only allowed in test/waitALL functions
 
invalid_status = ["NULL", "MPI_STATUSES_IGNORE"]
 
recv_funcs = ["mpi_recv"]
 
probe_recv_funcs = ["mpi_mprobe", "mpi_improbe"]
 
test_funcs = ["mpi_wait", "mpi_test", "mpi_waitall", "mpi_testall", "mpi_waitany", "mpi_testany", "mpi_waitsome",
 
"mpi_testsome"]
 
# , "mpi_testall", "mpi_testsome", "mpi_testany"]
 
sendrecv_funcs = ["mpi_sendrecv", "mpi_sendrecv_replace"]
 
 
def __init__(self):
 
pass
 
 
def get_feature(self):
 
return ["P2P"]
 
 
def generate_mprobe(self, probe_func, recv_func, test_probe, status):
 
send_func = "mpi_send"
 
 
func_to_test = recv_func
 
if test_probe:
 
func_to_test = probe_func
 
tm = get_send_recv_template(send_func, [probe_func, recv_func])
 
tm.set_description("InvalidParam-Status-" + func_to_test, "Invalid Status: %s" % status)
 
if status == "MPI_STATUSES_IGNORE":
 
tm.set_description("InvalidParam-Status-" + func_to_test,
 
"Invalid Status: %s\n wrong usage of status_ignore vs statusES_ignore" % status)
 
 
if test_probe:
 
for call in tm.get_instruction(identifier="MPICALL", return_list=True):
 
if call.get_rank_executing() == 0:
 
call.set_arg("status", status)
 
call.set_has_error()
 
else:
 
for call in tm.get_instruction(identifier="MATCHEDRECEIVE", return_list=True):
 
if call.get_rank_executing() == 0:
 
call.set_arg("status", status)
 
call.set_has_error()
 
 
return tm
 
 
def generate_probe(self, probe_to_use, status):
 
tm = get_send_recv_template("mpi_send", "mpi_recv")
 
tm.set_description("InvalidParam-Status-" + probe_to_use, "Invalid Status: %s" % status)
 
if status == "MPI_STATUSES_IGNORE":
 
tm.set_description("InvalidParam-Status-" + probe_to_use,
 
"Invalid Status: %s\n wrong usage of status_ignore vs statusES_ignore" % status)
 
 
probe_call = CorrectMPICallFactory.get(probe_to_use)
 
probe_call.set_arg("status", status)
 
probe_call.set_has_error()
 
probe_call.set_rank_executing(0)
 
 
if probe_to_use == "mpi_iprobe":
 
tm.add_stack_variable("int") # the flag
 
tm.insert_instruction(Instruction("int flag=0;", rank=0), before_instruction="MPICALL",
 
before_first_of_list=True)
 
tm.insert_instruction(Instruction("while (!flag){", rank=0), before_instruction="MPICALL",
 
before_first_of_list=True)
 
tm.insert_instruction(probe_call, before_instruction="MPICALL", before_first_of_list=True)
 
tm.insert_instruction(Instruction("}", rank=0), before_instruction="MPICALL",
 
before_first_of_list=True) # end while
 
else:
 
tm.insert_instruction(probe_call, before_instruction="MPICALL", before_first_of_list=True)
 
 
return tm
 
 
def generate(self, generate_full_set):
 
 
check_recv = True
 
send_func = "mpi_send"
 
recv_func = "mpi_recv"
 
for status in self.invalid_status:
 
tm = get_invalid_param_p2p_case("status", status, check_recv, send_func, recv_func)
 
tm.set_description("InvalidParam-Status-" + "mpi_recv", "Invalid Status: %s" % status)
 
if status == "MPI_STATUSES_IGNORE":
 
tm.set_description("InvalidParam-Status-" + "mpi_recv",
 
"Invalid Status: %s\n wrong usage of status_ignore vs statusES_ignore" % status)
 
yield tm
 
 
if not generate_full_set:
 
return
 
 
for wait_func in self.test_funcs:
 
for status in self.invalid_status:
 
tm = get_send_recv_template("mpi_send", "mpi_irecv")
 
tm.set_description("InvalidParam-Status-" + wait_func, "Invalid Status: %s" % status)
 
if status == "MPI_STATUSES_IGNORE":
 
tm.set_description("InvalidParam-Status-" + wait_func,
 
"Invalid Status: %s\n wrong usage of status_ignore vs statusES_ignore" % status)
 
# replace with wrong wait call
 
replace_wait(tm.get_instruction(identifier="WAIT"), tm, wait_func)
 
wait_call = tm.get_instruction(identifier="WAIT")
 
if wait_call.has_arg("status"):
 
wait_call.set_arg("status", status)
 
else:
 
s_to_use = status
 
if status == "MPI_STATUSES_IGNORE":
 
s_to_use = "MPI_STATUS_IGNORE"
 
wait_call.set_arg("array_of_statuses", s_to_use)
 
wait_call.set_has_error()
 
 
yield tm
 
 
for status in self.invalid_status:
 
yield self.generate_probe("mpi_probe", status)
 
yield self.generate_probe("mpi_iprobe", status)
 
yield self.generate_mprobe("mpi_mprobe", "mpi_mrecv", True, status)
 
yield self.generate_mprobe("mpi_mprobe", "mpi_mrecv", False, status)
 
yield self.generate_mprobe("mpi_improbe", "mpi_mrecv", True, status)
Loading