Select Git revision
MessageRace.py
MessageRace.py 3.79 KiB
#! /usr/bin/python3
from scripts.Infrastructure.ErrorGenerator import ErrorGenerator
from scripts.Infrastructure.InstructionBlock import InstructionBlock
from scripts.Infrastructure.MPICallFactory import MPICallFactory, CorrectMPICallFactory
from scripts.Infrastructure.CorrectParameter import CorrectParameterFactory, get_matching_recv
from scripts.Infrastructure.Template import TemplateManager
from scripts.Infrastructure.TemplateFactory import get_send_recv_template
from itertools import chain
class MessageRaceErrorAnyTag(ErrorGenerator):
# TODO do we need to generate it for all combinations of send and recv?
def __init__(self):
pass
def get_feature(self):
return ["P2P"]
def generate(self, generate_full_set):
tm = TemplateManager()
tm.set_description("MsgRace-ANY_TAG", "order of messages is indeterministic, may lead to a deadlock")
b = InstructionBlock("alloc")
b.register_instruction(CorrectParameterFactory().get_buffer_alloc())
tm.register_instruction_block(b)
b = InstructionBlock("MPICALL")
# send part
b.register_instruction("for(int i =0; i < 10; ++i) {", kind=1)
b.register_instruction("buf[0]=i;", kind=1)
send_call = CorrectMPICallFactory().mpi_send()
send_call.set_arg("tag", "i")
b.register_instruction(send_call, kind=1)
b.register_instruction("}", kind=1)
# recv part
b.register_instruction("for(int i =0; i < 10; ++i) {", kind=0)
recv_call = CorrectMPICallFactory().mpi_recv()
recv_call.set_arg("tag", "MPI_ANY_TAG")
b.register_instruction(recv_call, kind=0)
b.register_instruction("if(buf[0]!=i){", kind=0)
additional_recv = CorrectMPICallFactory().mpi_recv()
additional_recv.set_has_error() # additional recv leads to deadlock
b.register_instruction(additional_recv, kind=0)
b.register_instruction(" }", kind=0) # end if
b.register_instruction("}", kind=0) # end for
tm.register_instruction_block(b)
b = InstructionBlock("free")
b.register_instruction(CorrectParameterFactory().get_buffer_free())
tm.register_instruction_block(b)
yield tm
class MessageRaceErrorAnysource(ErrorGenerator):
# TODO do we need to generate it for all combinations of send and recv?
def __init__(self):
pass
def get_feature(self):
return ["P2P"]
def generate(self, generate_full_set):
tm = TemplateManager(min_ranks=3)
tm.set_description("MsgRace-ANY_SOURCE", "order of messages is indeterministic, may lead to a deadlock")
b = InstructionBlock("alloc")
b.register_instruction(CorrectParameterFactory().get_buffer_alloc())
tm.register_instruction_block(b)
b = InstructionBlock("MPICALL")
# send part
b.register_instruction("buf[0]=rank;", kind='not0')
send_call = CorrectMPICallFactory().mpi_send()
b.register_instruction(send_call, kind='not0')
# recv part
b.register_instruction("for(int i =1; i < nprocs; ++i) {", kind=0)
recv_call = CorrectMPICallFactory().mpi_recv()
recv_call.set_arg("source", "MPI_ANY_SOURCE")
b.register_instruction(recv_call, kind=0)
b.register_instruction("if(buf[0]!=i){", kind=0)
additional_recv = CorrectMPICallFactory().mpi_recv()
additional_recv.set_has_error() # additional recv leads to deadlock
b.register_instruction(additional_recv, kind=0)
b.register_instruction(" }", kind=0) # end if
b.register_instruction("}", kind=0) # end for
tm.register_instruction_block(b)
b = InstructionBlock("free")
b.register_instruction(CorrectParameterFactory().get_buffer_free())
tm.register_instruction_block(b)
yield tm