Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark Conversion of Ptrdist/ft #56

Merged
merged 2 commits into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions MultiSource/Benchmarks/Ptrdist/ft/Fheap.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
*/

#include <assert.h>
// CHECKED
#include <stdio_checked.h>
#include <stdlib_checked.h>
#include "Fheap.h"
#include "Fstruct.h"

#pragma BOUNDS_CHECKED ON

#ifdef DO_INLINE
#define INLINE inline
#else
Expand All @@ -59,7 +60,7 @@ void RemoveChild(_Ptr<HeapP> );
void FixRank(_Ptr<HeapP> , int);

INLINE void
InitFHeap()
InitFHeap(void)
{
int j;

Expand Down Expand Up @@ -143,7 +144,7 @@ DeleteMin(_Ptr<HeapP> h)

if(h1 == NULL)
{
free((void*)h);
free(h);
return(NULL);
}

Expand Down Expand Up @@ -265,7 +266,7 @@ DeleteMin(_Ptr<HeapP> h)
}
}

free((void*)h);
free(h);

return(min);
}
Expand Down Expand Up @@ -387,7 +388,7 @@ Delete(_Ptr<HeapP> h, _Ptr<HeapP> i)
while(h1 != CHILD(i));
}

free((void*)i);
free(i);
return(h);
}

Expand Down Expand Up @@ -498,11 +499,11 @@ NewHeap(_Ptr<Item> i)
{
_Ptr<HeapP> h = 0;

h = (HeapP *)calloc(1, sizeof(HeapP));
h = calloc(1, sizeof(HeapP));

if(h == NULL)
{
fprintf(stderr, "Oops, could not malloc\n");
_Unchecked { fprintf(stderr, "Oops, could not malloc\n"); }
exit(1);
}
ITEM(h) = i;
Expand Down
6 changes: 5 additions & 1 deletion MultiSource/Benchmarks/Ptrdist/ft/Fheap.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
*/
#include "item.h"

#pragma BOUNDS_CHECKED ON

typedef struct _Heap
{
_Ptr<Item> item;
Expand Down Expand Up @@ -78,7 +80,7 @@ typedef struct _Heap
* Return values:
* none
*/
void InitFHeap();
void InitFHeap(void);

/*
* Create a heap structure.
Expand Down Expand Up @@ -218,4 +220,6 @@ _Ptr<HeapP> Find(_Ptr<HeapP> h, _Ptr<Item> item);
*/
_Ptr<Item> ItemOf(_Ptr<HeapP> h);

#pragma BOUNDS_CHECKED OFF

#endif
11 changes: 7 additions & 4 deletions MultiSource/Benchmarks/Ptrdist/ft/Fsanity.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "Fheap.h"
#include "Fstruct.h"

#pragma BOUNDS_CHECKED ON

int
SanityCheck1(_Ptr<HeapP> h, _Ptr<Item> i)
{
Expand Down Expand Up @@ -149,22 +151,23 @@ PrettyPrint(_Ptr<HeapP> h)

if(h == NULL_HEAP)
{
printf(" nil ");
_Unchecked { printf(" nil "); }
return;
}

printf("(");
_Unchecked { printf("("); }

h1 = h;
do
{
//PrintItem(ITEM(h1));
printf("[%u] ", RANK(h1));
_Unchecked { printf("[%u] ", RANK(h1)); }
PrettyPrint(CHILD(h1));
h1 = FORWARD(h1);
}
while(h1 != h);

printf(")");
_Unchecked { printf(")"); }
}

#pragma BOUNDS_CHECKED OFF
4 changes: 4 additions & 0 deletions MultiSource/Benchmarks/Ptrdist/ft/Fsanity.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#ifndef _fsanity_h
#define _fsanity_h

#pragma BOUNDS_CHECKED ON

/*
* Check the entry ordering in the structure.
*
Expand Down Expand Up @@ -98,4 +100,6 @@ int SanityCheck3(_Ptr<Heap> h, int rank);
*/
void PrettyPrint(_Ptr<Heap> h);

#pragma BOUNDS_CHECKED OFF

#endif
4 changes: 4 additions & 0 deletions MultiSource/Benchmarks/Ptrdist/ft/Fstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#ifndef _fstruct_h
#define _fstruct_h

#pragma BOUNDS_CHECKED ON

#define ITEM(P) ((*(P)).item)
#define PARENT(P) ((*(P)).parent)
#define CHILD(P) ((*(P)).child)
Expand All @@ -55,4 +57,6 @@
#define FALSE 0
#define MAX_RANK 10000

#pragma BOUNDS_CHECKED OFF

#endif
22 changes: 12 additions & 10 deletions MultiSource/Benchmarks/Ptrdist/ft/ft.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include "Fheap.h"
#include "graph.h"

#pragma BOUNDS_CHECKED ON

#define MINUS_INFINITY INT_MIN
#define PLUS_INFINITY INT_MAX

Expand All @@ -65,9 +67,9 @@ _Ptr<Vertices> MST(_Ptr<Vertices> graph);
*/
int debug = 1;

int
_Unchecked int
main(int argc, _Array_ptr<const char*> argv : count(argc) )
{
_Checked {
int nVertex;
int nEdge;
_Ptr<Vertices> graph = 0;
Expand All @@ -76,7 +78,7 @@ main(int argc, _Array_ptr<const char*> argv : count(argc) )
nEdge = DEFAULT_N_EDGE;

if(argc > 1)
{
_Unchecked {
nVertex = atoi(argv[1]);
if(argc > 2)
{
Expand All @@ -89,30 +91,30 @@ main(int argc, _Array_ptr<const char*> argv : count(argc) )
}

if(debug)
{
_Unchecked {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to introduce a checked scope after the argument manipulation is done.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better, I added a checked scope for main, and an Unchecked scope just for the argument manipulation

printf("Generating a connected graph ... ");
}

graph = GenGraph(nVertex, nEdge);

if(debug)
{
_Unchecked {
printf("done\nFinding the mininmum spanning tree ... ");
}

graph = MST(graph);

if(debug)
{
printf("done\nThe graph:\n");
_Unchecked { printf("done\nThe graph:\n"); }
PrintGraph(graph);
printf("The minimum spanning tree:\n");
_Unchecked { printf("The minimum spanning tree:\n"); }
PrintMST(graph);
}

if(debug)
{
printf("Time spent in finding the mininum spanning tree:\n");
_Unchecked { printf("Time spent in finding the mininum spanning tree:\n"); }
}
#ifdef PLUS_STATS
PrintDerefStats(stderr);
Expand Down Expand Up @@ -142,7 +144,7 @@ MST(_Ptr<Vertices> graph)
vertex = graph;
KEY(vertex) = 0;
heap = MakeHeap();
(void)Insert(&heap, (Item *)vertex);
(void)Insert(&heap, vertex);

vertex = NEXT_VERTEX(vertex);
while(vertex != graph)
Expand Down Expand Up @@ -185,7 +187,7 @@ PrintMST(_Ptr<Vertices> graph)

while(vertex != graph)
{
printf("vertex %d to %d\n", ID(vertex), ID(SOURCE(CHOSEN_EDGE(vertex))));
_Unchecked { printf("vertex %d to %d\n", ID(vertex), ID(SOURCE(CHOSEN_EDGE(vertex)))); }
vertex = NEXT_VERTEX(vertex);
}

Expand Down
12 changes: 7 additions & 5 deletions MultiSource/Benchmarks/Ptrdist/ft/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <stdlib_checked.h>
#include "graph.h"

#pragma BOUNDS_CHECKED ON

#define TRUE 1
#define FALSE 0

Expand Down Expand Up @@ -228,7 +230,7 @@ NewVertex(void)

if(vertex == NULL)
{
fprintf(stderr, "Could not malloc\n");
_Unchecked { fprintf(stderr, "Could not malloc\n"); }
exit(1);
}

Expand All @@ -248,7 +250,7 @@ NewEdge(void)

if(edge == NULL)
{
fprintf(stderr, "Could not malloc\n");
_Unchecked { fprintf(stderr, "Could not malloc\n"); }
exit(1);
}

Expand All @@ -269,9 +271,9 @@ PrintGraph(_Ptr<Vertices> graph)
vertex = graph;
do
{
printf("Vertex %d is connected to:", ID(vertex));
_Unchecked { printf("Vertex %d is connected to:", ID(vertex)); }
PrintNeighbors(vertex);
printf("\n");
_Unchecked { printf("\n"); }
vertex = NEXT_VERTEX(vertex);
}
while(vertex != graph);
Expand All @@ -285,7 +287,7 @@ PrintNeighbors(_Ptr<Vertices> vertex)
edge = EDGES(vertex);
while(edge != NULL)
{
printf(" %d(%d)[%d]", ID(VERTEX(edge)), WEIGHT(edge), ID(SOURCE(edge)));
_Unchecked { printf(" %d(%d)[%d]", ID(VERTEX(edge)), WEIGHT(edge), ID(SOURCE(edge))); }
edge = NEXT_EDGE(edge);
}
}
Expand Down
4 changes: 4 additions & 0 deletions MultiSource/Benchmarks/Ptrdist/ft/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#ifndef _graph_h
#define _graph_h

#pragma BOUNDS_CHECKED ON

struct _Vertices;

typedef struct _Edges
Expand Down Expand Up @@ -75,4 +77,6 @@ typedef struct _Vertices
_Ptr<Vertices> GenGraph(int nVertex, int nEdge);
void PrintGraph(_Ptr<Vertices> graph);

#pragma BOUNDS_CHECKED OFF

#endif
2 changes: 2 additions & 0 deletions MultiSource/Benchmarks/Ptrdist/ft/item.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include "item.h"

#pragma BOUNDS_CHECKED ON

int LessThan(_Ptr<Item> item1, _Ptr<Item> item2)
{
return(KEY(item1) < KEY(item2));
Expand Down
4 changes: 4 additions & 0 deletions MultiSource/Benchmarks/Ptrdist/ft/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#include "graph.h"

#pragma BOUNDS_CHECKED ON

typedef Vertices Item;

#define NULL_ITEM NULL_VERTEX
Expand All @@ -41,4 +43,6 @@ int LessThan(_Ptr<Item> , _Ptr<Item> );
int Equal(_Ptr<Item> , _Ptr<Item> );
_Ptr<Item> Subtract(_Ptr<Item> , int);

#pragma BOUNDS_CHECKED OFF

#endif