Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MPI-BugBench
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
High Performance Computing - Public
MPI-BugBench
Commits
c01e9805
Commit
c01e9805
authored
Jan 26, 2024
by
Jammer, Tim
Browse files
Options
Downloads
Patches
Plain Diff
Added Alloc Call Class for easy manipulation of Allocations
parent
e77b3d66
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/Infrastructure/AllocCall.py
+85
-0
85 additions, 0 deletions
scripts/Infrastructure/AllocCall.py
with
85 additions
and
0 deletions
scripts/Infrastructure/AllocCall.py
0 → 100644
+
85
−
0
View file @
c01e9805
#! /usr/bin/python3
alloc_template
=
"""
@{NAME}@ = (@{TYPE}@*) @{FUNCTION}@(@{NUM}@ @{SEP}@ sizeof(@{TYPE}@));
"""
"""
Class Overview:
The `AllocCall` class is a helper for creationg allocation calls (with malloc or calloc)
Methods:
- `__init__(self)`: Initializes a new Alloc Call
- `__str__(self)`: Converts the AllocCall instance to a string, replacing placeholders.
- `set_num_elements(self, num_elements)`: Sets number of elements to allocate
- `set_type(self, type)`: Sets the type of allocated elements
- `set_name(self, name)`: Sets the name of allocated variable
- `set_use_calloc(self)`: Use calloc
- `set_use_malloc(self)`: Use malloc
"""
class
AllocCall
:
def
__init__
(
self
,
type
,
num_elements
,
name
=
"
buf
"
,
use_malloc
=
False
):
"""
Creates a New allocation Call
Args:
type: Type to allocate (int not MPI_INT)
num_elements: number of buffer elements
name: name of buffer variable
use_malloc: True: use Malloc, False: use calloc for allocation
"""
self
.
_use_malloc
=
use_malloc
self
.
_type
=
type
self
.
_num_elements
=
num_elements
self
.
_name
=
name
def
__str__
(
self
):
if
self
.
_use_malloc
:
delim
=
'
*
'
func
=
"
malloc
"
else
:
delim
=
'
,
'
func
=
"
calloc
"
return
(
alloc_template
.
replace
(
"
@{NAME}@
"
,
self
.
_name
)
.
replace
(
"
@{TYPE}@
"
,
self
.
_type
)
.
replace
(
"
@{FUNCTION}@
"
,
func
)
.
replace
(
"
@{NUM}@
"
,
self
.
_num_elements
)
.
replace
(
"
@{SEP}
"
,
delim
))
def
set_num_elements
(
self
,
num_elements
):
self
.
_num_elements
=
num_elements
def
set_name
(
self
,
name
):
self
.
_name
=
name
def
set_type
(
self
,
type
):
self
.
_type
=
type
def
set_use_malloc
(
self
):
self
.
_use_malloc
=
True
def
set_use_calloc
(
self
):
self
.
_use_malloc
=
False
def
get_num_elements
(
self
):
return
self
.
_num_elements
def
get_name
(
self
):
return
self
.
_name
def
get_type
(
self
):
return
self
.
_type
def
get_use_malloc
(
self
):
return
self
.
_use_malloc
def
get_free
(
alloc_call
):
assert
isinstance
(
alloc_call
,
AllocCall
)
return
"
free(
"
+
alloc_call
.
get_name
()
+
"
);
\n
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment