Skip to content
Snippets Groups Projects
Commit 14b74753 authored by Tim Jammer's avatar Tim Jammer
Browse files

Refactoring: Split into multiple Files

parent e478069d
No related branches found
No related tags found
1 merge request!1Initial template infrastructure
Pipeline #351311 failed
#! /usr/bin/python3
from scripts.Infrastructure.MPICallFactroy import Correct_Parameter, MPI_Call_Factory, get_matching_recv
from scripts.Infrastructure.Template import TemplateManager, InstructionBlock
class Invalid_negative_rank_error:
invalid_ranks = ["-1", "size", "NULL", "MPI_PROC_NULL"]
def __init__(self, rank_to_use):
self.rank_to_use = rank_to_use
pass
def __call__(self):
tm = TemplateManager()
correct_params = Correct_Parameter()
tm.set_description("Invalid Rank: %s" % self.invalid_ranks[self.rank_to_use])
# include the buffer allocation in the template (all ranks execute it)
tm.register_instruction_block(correct_params.get_buffer_alloc())
send = MPI_Call_Factory().mpi_send(
correct_params.get("BUFFER"),
correct_params.get("COUNT"),
correct_params.get("DATATYPE"),
self.invalid_ranks[self.rank_to_use], # invalid rank
correct_params.get("TAG"),
correct_params.get("COMM"),
)
send.set_has_error()
b = InstructionBlock()
# only rank 0 execute the send
b.register_operation(send, 0)
# only rank 1 execute the recv
b.register_operation(get_matching_recv(send), 1)
tm.register_instruction_block(b)
return tm
if __name__ == "__main__":
print("generate:")
print(Invalid_negative_rank_error(0)())
print("generate:")
print(Invalid_negative_rank_error(1)())
print("generate:")
print(Invalid_negative_rank_error(2)())
print("generate: is this a differend kind of error (deadlock)")
print(Invalid_negative_rank_error(3)())
pass
#! /usr/bin/python3
from scripts.Infrastructure.Variables import ERROR_MARKER_COMMENT
class MPI_Call:
def __init__(self, function, args, version):
self._function = function
self._args = args
self._version = version
self._has_error = False
def __str__(self):
s = self._function + "("
for k, v in self._args.items():
assert v is not None
s += str(v) + ", "
s = s[:-2] # remove last , and space
s += ");"
if self._has_error:
s += ERROR_MARKER_COMMENT
return s
def set_arg(self, arg, value):
assert self.has_arg(arg)
self._args[arg] = value
def has_arg(self, arg):
return arg in self._args
def get_version(self):
return self._version
def set_has_error(self, has_error=True):
self._has_error = has_error
#! /usr/bin/python3
from collections import OrderedDict
from scripts.Infrastructure.MPICall import MPI_Call
from scripts.Infrastructure.Template import InstructionBlock
class MPI_Call_Factory:
# one could generate the MPI Factory from the Standards JSON
def mpi_send(self, *args):
return MPI_Call("MPI_Send",
OrderedDict([("BUFFER", args[0]), ("COUNT", args[1]), ("DATATYPE", args[2]), ("SRC", args[3]),
("TAG", args[4]), ("COMM", args[5])]),
"1.0")
def mpi_recv(self, *args):
return MPI_Call("MPI_Recv",
OrderedDict([("BUFFER", args[0]), ("COUNT", args[1]), ("DATATYPE", args[2]), ("SRC", args[3]),
("TAG", args[4]), ("COMM", args[5]), ("STATUS", args[6])]),
"1.0")
class Correct_Parameter:
# default params
buf_size = 10
dtype = ['int', 'MPI_INT']
tag = 0
def __init__(self):
pass
def get_buffer_alloc(self):
b = InstructionBlock()
b.register_operation_all(("int* buf = (int*) malloc(%d* sizeof(%s));" % (self.buf_size, self.dtype[0])))
return b
def get(self, param, func=None):
if param == "BUFFER":
return "buf"
if param == "COUNT":
return str(self.buf_size)
if param == "DATATYPE":
return self.dtype[1]
if param == "SRC":
return "0"
if param == "TAG":
return str(self.tag)
if param == "COMM":
return "MPI_COMM_WORLD"
if param == "STATUS":
return "MPI_STATUS_IGNORE"
assert False, "Param not known"
# todo also for send and non default args
def get_matching_recv(call):
correct_params = Correct_Parameter()
recv = MPI_Call_Factory().mpi_recv(
correct_params.get("BUFFER"),
correct_params.get("COUNT"),
correct_params.get("DATATYPE"),
correct_params.get("SRC"),
correct_params.get("TAG"),
correct_params.get("COMM"),
correct_params.get("STATUS", "MPI_Recv"),
)
return recv
#! /usr/bin/python3
import os
import sys
from collections import OrderedDict
from scripts.Infrastructure.MPICall import MPI_Call
template = """// @{generatedby}@
/* ///////////////////////// The MPI Bug Bench ////////////////////////
......@@ -63,58 +61,6 @@ template_instruction_block = """
@{operation_all}@
"""
error_Comment = "/*MBBERROR*/"
class MPI_Call:
def __init__(self, function, args, version):
self._function = function
self._args = args
self._version = version
self._has_error = False
def __str__(self):
s = self._function + "("
for k, v in self._args.items():
assert v is not None
s += str(v) + ", "
s = s[:-2] # remove last , and space
s += ");"
if self._has_error:
s += error_Comment
return s
def set_arg(self, arg, value):
assert self.has_arg(arg)
self._args[arg] = value
def has_arg(self, arg):
return arg in self._args
def get_version(self):
return self._version
def set_has_error(self, has_error=True):
self._has_error = has_error
class MPI_Call_Factory:
# one could generate the MPI Factory from the Standards JSON
def mpi_send(self, *args):
return MPI_Call("MPI_Send",
OrderedDict([("BUFFER", args[0]), ("COUNT", args[1]), ("DATATYPE", args[2]), ("SRC", args[3]),
("TAG", args[4]), ("COMM", args[5])]),
"1.0")
def mpi_recv(self, *args):
return MPI_Call("MPI_Recv",
OrderedDict([("BUFFER", args[0]), ("COUNT", args[1]), ("DATATYPE", args[2]), ("SRC", args[3]),
("TAG", args[4]), ("COMM", args[5]), ("STATUS", args[6])]),
"1.0")
class TemplateManager:
def __init__(self):
self._descr = ""
......@@ -195,103 +141,3 @@ class InstructionBlock:
.replace("@{operation_rank0}@", op_0_string)
.replace("@{operation_rank1}@", op_1_string)
.replace("@{operation_all}@", op_all_string))
class Correct_Parameter:
# default params
buf_size = 10
dtype = ['int', 'MPI_INT']
tag = 0
def __init__(self):
pass
def get_buffer_alloc(self):
b = InstructionBlock()
b.register_operation_all(("int* buf = (int*) malloc(%d* sizeof(%s));" % (self.buf_size, self.dtype[0])))
return b
def get(self, param, func=None):
if param == "BUFFER":
return "buf"
if param == "COUNT":
return str(self.buf_size)
if param == "DATATYPE":
return self.dtype[1]
if param == "SRC":
return "0"
if param == "TAG":
return str(self.tag)
if param == "COMM":
return "MPI_COMM_WORLD"
if param == "STATUS":
return "MPI_STATUS_IGNORE"
assert False, "Param not known"
# todo also for send and non default args
def get_matching_recv(call):
correct_params = Correct_Parameter()
recv = MPI_Call_Factory().mpi_recv(
correct_params.get("BUFFER"),
correct_params.get("COUNT"),
correct_params.get("DATATYPE"),
correct_params.get("SRC"),
correct_params.get("TAG"),
correct_params.get("COMM"),
correct_params.get("STATUS", "MPI_Recv"),
)
return recv
# one could parameterize even more:
# the function to use
# wether to use a Variable to give the invalid parameter (one can even extend the template to allow for the variable to be hidden in a different function)
class Invalid_negative_rank_error:
invalid_ranks = ["-1", "size", "NULL", "MPI_PROC_NULL"]
def __init__(self, rank_to_use):
self.rank_to_use = rank_to_use
pass
def __call__(self):
tm = TemplateManager()
correct_params = Correct_Parameter()
tm.set_description("Invalid Rank: %s" % self.invalid_ranks[self.rank_to_use])
# include the buffer allocation in the template (all ranks execute it)
tm.register_instruction_block(correct_params.get_buffer_alloc())
send = MPI_Call_Factory().mpi_send(
correct_params.get("BUFFER"),
correct_params.get("COUNT"),
correct_params.get("DATATYPE"),
self.invalid_ranks[self.rank_to_use], # invalid rank
correct_params.get("TAG"),
correct_params.get("COMM"),
)
send.set_has_error()
b = InstructionBlock()
# only rank 0 execute the send
b.register_operation(send, 0)
# only rank 1 execute the recv
b.register_operation(get_matching_recv(send), 1)
tm.register_instruction_block(b)
return tm
if __name__ == "__main__":
print("generate:")
print(Invalid_negative_rank_error(0)())
print("generate:")
print(Invalid_negative_rank_error(1)())
print("generate:")
print(Invalid_negative_rank_error(2)())
print("generate: is this a differend kind of error (deadlock)")
print(Invalid_negative_rank_error(3)())
pass
#! /usr/bin/python3
ERROR_MARKER_COMMENT = "/*MBBERROR*/"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment