Skip to content

Commit 9b43de1

Browse files
authored
Merge pull request #4014 from bosilca/topic/treematch
Topic/treematch
2 parents 628b4f7 + 3d27e0d commit 9b43de1

38 files changed

+5416
-3063
lines changed

ompi/mca/topo/treematch/Makefile.am

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,25 @@
1313

1414
if topo_treematch_local
1515
extra_treematch_files = treematch/tm_bucket.h \
16-
treematch/tm_hwloc.h treematch/tm_mapping.h \
16+
treematch/tm_mapping.h \
1717
treematch/tm_timings.h treematch/tm_tree.h \
1818
treematch/tm_kpartitioning.h treematch/uthash.h\
1919
treematch/IntConstantInitializedVector.h \
20-
treematch/tm_mt.h \
20+
treematch/tm_mt.h treematch/fibo.h \
2121
treematch/tm_thread_pool.h treematch/tm_verbose.h \
22-
treematch/tm_malloc.h \
22+
treematch/tm_malloc.h treematch/k-partitioning.h\
23+
treematch/tm_solution.h treematch/tm_topology.h\
24+
treematch/PriorityQueue.h \
2325
treematch/IntConstantInitializedVector.c \
24-
treematch/tm_mt.c \
26+
treematch/tm_mt.c treematch/fibo.c \
2527
treematch/tm_thread_pool.c treematch/tm_verbose.c \
26-
treematch/tm_malloc.c \
28+
treematch/tm_malloc.c treematch/treematch.h \
2729
treematch/tm_mapping.c treematch/tm_timings.c \
2830
treematch/tm_bucket.c treematch/tm_tree.c \
29-
treematch/tm_hwloc.c treematch/tm_kpartitioning.c
31+
treematch/tm_topology.c treematch/tm_kpartitioning.c \
32+
treematch/tm_solution.c treematch/k-partitioning.c \
33+
treematch/PriorityQueue.c
34+
EXTRA_DIST = treematch/COPYING treematch/LICENSE
3035
endif
3136

3237
sources = \

ompi/mca/topo/treematch/topo_treematch_component.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ mca_topo_treematch_component_2_2_0_t mca_topo_treematch_component =
6262

6363
static int init_query(bool enable_progress_threads, bool enable_mpi_threads)
6464
{
65+
if(NULL == opal_hwloc_topology) {
66+
return OPAL_ERR_NOT_SUPPORTED;
67+
}
6568
return OMPI_SUCCESS;
6669
}
6770

@@ -95,3 +98,4 @@ static int mca_topo_treematch_component_register(void)
9598
MCA_BASE_VAR_SCOPE_READONLY, &mca_topo_treematch_component.reorder_mode);
9699
return OMPI_SUCCESS;
97100
}
101+

ompi/mca/topo/treematch/topo_treematch_dist_graph_create.c

Lines changed: 335 additions & 382 deletions
Large diffs are not rendered by default.

ompi/mca/topo/treematch/treematch/IntConstantInitializedVector.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
#include <stdio.h>
33
#include "IntConstantInitializedVector.h"
44

5-
65
int intCIV_isInitialized(int_CIVector * v, int i)
76
{
87
if(v->top == 0)
98
return 0;
109
if(v->from[i] >= 0)
11-
if(v->from[i] < v->top && v->to[v->from[i]] == i)
10+
if(v->from[i] < v->top && v->to[v->from[i]] == i)
1211
return 1;
1312
return 0;
1413
}
@@ -45,7 +44,7 @@ int intCIV_set(int_CIVector * v, int i, int val)
4544
v->top++;
4645
}
4746
v->vec[i] = val;
48-
return 0;
47+
return 0;
4948
}
5049

5150
int intCIV_get(int_CIVector * v, int i)

ompi/mca/topo/treematch/treematch/IntConstantInitializedVector.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ void intCIV_exit(int_CIVector * v);
1212
int intCIV_set(int_CIVector * v, int i, int val);
1313
int intCIV_get(int_CIVector * v, int i);
1414

15-
1615
#endif /*INTEGER_CONSTANT_INITIALIZED_VECTOR*/
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#include <stdlib.h>
2+
#include "PriorityQueue.h"
3+
4+
/*
5+
This comparison function is used to sort elements in key descending order.
6+
*/
7+
static int compFunc(const FiboNode * const node1, const FiboNode * const node2)
8+
{
9+
return
10+
( ( ((QueueElement*)(node1))->key > ((QueueElement*)(node2))->key ) ? -1 : 1);
11+
}
12+
13+
int PQ_init(PriorityQueue * const q, int size)
14+
{
15+
int i;
16+
q->size = size;
17+
q->elements = malloc(sizeof(QueueElement *) * size);
18+
for(i=0; i < size; i++)
19+
q->elements[i]=NULL;
20+
return fiboTreeInit((FiboTree *)q, compFunc);
21+
}
22+
23+
void PQ_exit(PriorityQueue * const q)
24+
{
25+
26+
int i;
27+
for(i = 0; i < q->size; i++)
28+
{
29+
if(q->elements[i] != NULL)
30+
free(q->elements[i]);
31+
}
32+
if(q->elements != NULL)
33+
free(q->elements);
34+
fiboTreeExit((FiboTree *)q);
35+
}
36+
void PQ_free(PriorityQueue * const q)
37+
{
38+
int i;
39+
for(i = 0; i < q->size; i++)
40+
{
41+
if(q->elements[i] != NULL)
42+
free(q->elements[i]);
43+
}
44+
fiboTreeFree((FiboTree *)q);
45+
}
46+
47+
int PQ_isEmpty(PriorityQueue * const q)
48+
{
49+
FiboTree * tree = (FiboTree *)q;
50+
/* if the tree root is linked to itself then the tree is empty */
51+
if(&(tree->rootdat) == (tree->rootdat.linkdat.nextptr))
52+
return 1;
53+
return 0;
54+
}
55+
56+
void PQ_insertElement(PriorityQueue * const q, QueueElement * const e)
57+
{
58+
if(e->value >= 0 && e->value < q->size)
59+
{
60+
fiboTreeAdd((FiboTree *)q, (FiboNode *)(e));
61+
q->elements[e->value] = e;
62+
e->isInQueue = 1;
63+
}
64+
}
65+
void PQ_deleteElement(PriorityQueue * const q, QueueElement * const e)
66+
{
67+
fiboTreeDel((FiboTree *)q, (FiboNode *)(e));
68+
q->elements[e->value] = NULL;
69+
e->isInQueue = 0;
70+
}
71+
72+
void PQ_insert(PriorityQueue * const q, int val, double key)
73+
{
74+
if( val >= 0 && val < q->size)
75+
{
76+
QueueElement * e = malloc(sizeof(QueueElement));
77+
e->value = val;
78+
e->key = key;
79+
PQ_insertElement(q, e);
80+
}
81+
}
82+
83+
void PQ_delete(PriorityQueue * const q, int val)
84+
{
85+
QueueElement * e = q->elements[val];
86+
PQ_deleteElement(q, e);
87+
free(e);
88+
}
89+
90+
QueueElement * PQ_findMaxElement(PriorityQueue * const q)
91+
{
92+
QueueElement * e = (QueueElement *)(fiboTreeMin((FiboTree *)q));
93+
return e;
94+
}
95+
QueueElement * PQ_deleteMaxElement(PriorityQueue * const q)
96+
{
97+
QueueElement * e = (QueueElement *)(fiboTreeMin((FiboTree *)q));
98+
if(e != NULL)
99+
{
100+
PQ_deleteElement(q, e);
101+
}
102+
return e;
103+
}
104+
105+
double PQ_findMaxKey(PriorityQueue * const q)
106+
{
107+
QueueElement * e = PQ_findMaxElement(q);
108+
if(e!=NULL)
109+
return e->key;
110+
return 0;
111+
}
112+
113+
int PQ_deleteMax(PriorityQueue * const q)
114+
{
115+
QueueElement * e = PQ_deleteMaxElement(q);
116+
int res = -1;
117+
if(e != NULL)
118+
res = e->value;
119+
free(e);
120+
return res;
121+
}
122+
123+
void PQ_increaseElementKey(PriorityQueue * const q, QueueElement * const e, double i)
124+
{
125+
if(e->isInQueue)
126+
{
127+
PQ_deleteElement(q, e);
128+
e->key += i;
129+
PQ_insertElement(q, e);
130+
}
131+
}
132+
void PQ_decreaseElementKey(PriorityQueue * const q, QueueElement * const e, double i)
133+
{
134+
if(e->isInQueue)
135+
{
136+
PQ_deleteElement(q, e);
137+
e->key -= i;
138+
PQ_insertElement(q, e);
139+
}
140+
}
141+
void PQ_adjustElementKey(PriorityQueue * const q, QueueElement * const e, double i)
142+
{
143+
if(e->isInQueue)
144+
{
145+
PQ_deleteElement(q, e);
146+
e->key = i;
147+
PQ_insertElement(q, e);
148+
}
149+
}
150+
151+
void PQ_increaseKey(PriorityQueue * const q, int val, double i)
152+
{
153+
QueueElement * e = q->elements[val];
154+
if(e != NULL)
155+
PQ_increaseElementKey(q, e, i);
156+
}
157+
158+
void PQ_decreaseKey(PriorityQueue * const q, int val, double i)
159+
{
160+
QueueElement * e = q->elements[val];
161+
if(e != NULL)
162+
PQ_decreaseElementKey(q, e, i);
163+
}
164+
165+
void PQ_adjustKey(PriorityQueue * const q, int val, double i)
166+
{
167+
QueueElement * e = q->elements[val];
168+
if(e != NULL)
169+
PQ_adjustElementKey(q, e, i);
170+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#ifndef PRIORITY_QUEUE
2+
#define PRIORITY_QUEUE
3+
4+
#include "fibo.h"
5+
6+
/*
7+
This is the struct for our elements in a PriorityQueue.
8+
The node is at first place so we only have to use a cast to switch between QueueElement's pointer and Fibonode's pointer.
9+
*/
10+
typedef struct QueueElement_
11+
{
12+
FiboNode node; /*the node used to insert the element in a FiboTree*/
13+
double key; /*the key of the element, elements are sorted in a descending order according to their key*/
14+
int value;
15+
int isInQueue;
16+
} QueueElement;
17+
18+
typedef struct PriorityQueue_
19+
{
20+
FiboTree tree;
21+
QueueElement ** elements; /*a vector of element with their value as key so we can easily retreive an element from its value */
22+
int size; /*the size allocated to the elements vector*/
23+
} PriorityQueue;
24+
25+
26+
/*
27+
PQ_init initiates a PriorityQueue with a size given in argument and sets compFunc as comparison function. Note that you have to allocate memory to the PriorityQueue pointer before calling this function.
28+
Returns :
29+
0 if success
30+
!0 if failed
31+
32+
PQ_free simply empties the PriorityQueue but does not free the memory used by its elements.
33+
PQ_exit destroys the PriorityQueue without freeing elements. The PriorityQueue is no longer usable without using PQ_init again.
34+
Note that the PriorityQueue pointer is not deallocated.
35+
*/
36+
int PQ_init(PriorityQueue * const, int size);
37+
void PQ_free(PriorityQueue * const);
38+
void PQ_exit(PriorityQueue * const);
39+
40+
/*
41+
PQ_isEmpty returns 1 if the PriorityQueue is empty, 0 otherwise.
42+
*/
43+
int PQ_isEmpty(PriorityQueue * const);
44+
45+
/*
46+
PQ_insertElement inserts the given QueueElement in the given PriorityQueue
47+
*/
48+
void PQ_insertElement(PriorityQueue * const, QueueElement * const);
49+
/*
50+
PQ_deleteElement delete the element given in argument from the PriorityQueue.
51+
*/
52+
void PQ_deleteElement(PriorityQueue * const, QueueElement * const);
53+
54+
/*
55+
PQ_insert inserts an element in the PriorityQueue with the value and key given in argument.
56+
*/
57+
void PQ_insert(PriorityQueue * const, int val, double key);
58+
/*
59+
PQ_delete removes the first element found with the value given in argument and frees it.
60+
*/
61+
void PQ_delete(PriorityQueue * const, int val);
62+
63+
64+
/*
65+
PQ_findMaxElement returns the QueueElement with the greatest key in the given PriorityQueue
66+
*/
67+
QueueElement * PQ_findMaxElement(PriorityQueue * const);
68+
/*
69+
PQ_deleteMaxElement returns the QueueElement with the geatest key in the given PriorityQueue and removes it from the queue.
70+
*/
71+
QueueElement * PQ_deleteMaxElement(PriorityQueue * const);
72+
73+
/*
74+
PQ_findMax returns the key of the element with the geatest key in the given PriorityQueue
75+
*/
76+
double PQ_findMaxKey(PriorityQueue * const);
77+
/*
78+
PQ_deleteMax returns the value of the element with the greatest key in the given PriorityQueue and removes it from the queue.
79+
*/
80+
int PQ_deleteMax(PriorityQueue * const);
81+
82+
/*
83+
PQ_increaseElementKey adds the value of i to the key of the given QueueElement
84+
*/
85+
void PQ_increaseElementKey(PriorityQueue * const, QueueElement * const, double i);
86+
/*
87+
PQ_decreaseElementKey substracts the value of i from the key of the given QueueElement
88+
*/
89+
void PQ_decreaseElementKey(PriorityQueue * const, QueueElement * const, double i);
90+
/*
91+
PQ_adjustElementKey sets to i the key of the given QueueElement.
92+
*/
93+
void PQ_adjustElementKey(PriorityQueue * const, QueueElement * const, double i);
94+
95+
/*
96+
PQ_increaseKey adds i to the key of the first element found with a value equal to val in the PriorityQueue.
97+
*/
98+
void PQ_increaseKey(PriorityQueue * const, int val, double i);
99+
/*
100+
PQ_decreaseKey substracts i from the key of the first element found with a value equal to val in the PriorityQueue.
101+
*/
102+
void PQ_decreaseKey(PriorityQueue * const, int val, double i);
103+
/*
104+
PQ_adjustKey sets to i the key of the first element found with a value equal to val in the PriorityQueue.
105+
*/
106+
void PQ_adjustKey(PriorityQueue * const, int val, double i);
107+
108+
#endif /*PRIORITY_QUEUE*/

0 commit comments

Comments
 (0)