Skip to content

Commit c2927d7

Browse files
committed
Update to the latest version provided by Guillaume.
Signed-off-by: George Bosilca <[email protected]>
1 parent 6c8ea09 commit c2927d7

39 files changed

+5272
-2804
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.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int mca_topo_treematch_dist_graph_create(mca_topo_base_module_t* module,
7070
int n, const int nodes[],
7171
const int degrees[], const int targets[],
7272
const int weights[],
73-
struct opal_info_t *info, int reorder,
73+
struct ompi_info_t *info, int reorder,
7474
ompi_communicator_t **newcomm);
7575
/*
7676
* ******************************************************************

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: 160 additions & 122 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: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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+
int compfunc(const FiboNode * const, const FiboNode * const);
8+
9+
10+
11+
int compFunc(const FiboNode * const node1, const FiboNode * const node2)
12+
{
13+
return
14+
( ( ((QueueElement*)(node1))->key > ((QueueElement*)(node2))->key ) ? -1 : 1);
15+
}
16+
17+
int PQ_init(PriorityQueue * const q, int size)
18+
{
19+
int i;
20+
q->size = size;
21+
q->elements = malloc(sizeof(QueueElement *) * size);
22+
for(i=0; i < size; i++)
23+
q->elements[i]=NULL;
24+
return fiboTreeInit((FiboTree *)q, compFunc);
25+
}
26+
27+
void PQ_exit(PriorityQueue * const q)
28+
{
29+
30+
int i;
31+
for(i = 0; i < q->size; i++)
32+
{
33+
if(q->elements[i] != NULL)
34+
free(q->elements[i]);
35+
}
36+
if(q->elements != NULL)
37+
free(q->elements);
38+
fiboTreeExit((FiboTree *)q);
39+
}
40+
void PQ_free(PriorityQueue * const q)
41+
{
42+
int i;
43+
for(i = 0; i < q->size; i++)
44+
{
45+
if(q->elements[i] != NULL)
46+
free(q->elements[i]);
47+
}
48+
fiboTreeFree((FiboTree *)q);
49+
}
50+
51+
int PQ_isEmpty(PriorityQueue * const q)
52+
{
53+
FiboTree * tree = (FiboTree *)q;
54+
/* if the tree root is linked to itself then the tree is empty */
55+
if(&(tree->rootdat) == (tree->rootdat.linkdat.nextptr))
56+
return 1;
57+
return 0;
58+
}
59+
60+
void PQ_insertElement(PriorityQueue * const q, QueueElement * const e)
61+
{
62+
if(e->value >= 0 && e->value < q->size)
63+
{
64+
fiboTreeAdd((FiboTree *)q, (FiboNode *)(e));
65+
q->elements[e->value] = e;
66+
e->isInQueue = 1;
67+
}
68+
}
69+
void PQ_deleteElement(PriorityQueue * const q, QueueElement * const e)
70+
{
71+
fiboTreeDel((FiboTree *)q, (FiboNode *)(e));
72+
q->elements[e->value] = NULL;
73+
e->isInQueue = 0;
74+
}
75+
76+
void PQ_insert(PriorityQueue * const q, int val, double key)
77+
{
78+
if( val >= 0 && val < q->size)
79+
{
80+
QueueElement * e = malloc(sizeof(QueueElement));
81+
e->value = val;
82+
e->key = key;
83+
PQ_insertElement(q, e);
84+
}
85+
}
86+
87+
void PQ_delete(PriorityQueue * const q, int val)
88+
{
89+
QueueElement * e = q->elements[val];
90+
PQ_deleteElement(q, e);
91+
free(e);
92+
}
93+
94+
QueueElement * PQ_findMaxElement(PriorityQueue * const q)
95+
{
96+
QueueElement * e = (QueueElement *)(fiboTreeMin((FiboTree *)q));
97+
return e;
98+
}
99+
QueueElement * PQ_deleteMaxElement(PriorityQueue * const q)
100+
{
101+
QueueElement * e = (QueueElement *)(fiboTreeMin((FiboTree *)q));
102+
if(e != NULL)
103+
{
104+
PQ_deleteElement(q, e);
105+
}
106+
return e;
107+
}
108+
109+
double PQ_findMaxKey(PriorityQueue * const q)
110+
{
111+
QueueElement * e = PQ_findMaxElement(q);
112+
if(e!=NULL)
113+
return e->key;
114+
return 0;
115+
}
116+
117+
int PQ_deleteMax(PriorityQueue * const q)
118+
{
119+
QueueElement * e = PQ_deleteMaxElement(q);
120+
int res = -1;
121+
if(e != NULL)
122+
res = e->value;
123+
free(e);
124+
return res;
125+
}
126+
127+
void PQ_increaseElementKey(PriorityQueue * const q, QueueElement * const e, double i)
128+
{
129+
if(e->isInQueue)
130+
{
131+
PQ_deleteElement(q, e);
132+
e->key += i;
133+
PQ_insertElement(q, e);
134+
}
135+
}
136+
void PQ_decreaseElementKey(PriorityQueue * const q, QueueElement * const e, double i)
137+
{
138+
if(e->isInQueue)
139+
{
140+
PQ_deleteElement(q, e);
141+
e->key -= i;
142+
PQ_insertElement(q, e);
143+
}
144+
}
145+
void PQ_adjustElementKey(PriorityQueue * const q, QueueElement * const e, double i)
146+
{
147+
if(e->isInQueue)
148+
{
149+
PQ_deleteElement(q, e);
150+
e->key = i;
151+
PQ_insertElement(q, e);
152+
}
153+
}
154+
155+
void PQ_increaseKey(PriorityQueue * const q, int val, double i)
156+
{
157+
QueueElement * e = q->elements[val];
158+
if(e != NULL)
159+
PQ_increaseElementKey(q, e, i);
160+
}
161+
162+
void PQ_decreaseKey(PriorityQueue * const q, int val, double i)
163+
{
164+
QueueElement * e = q->elements[val];
165+
if(e != NULL)
166+
PQ_decreaseElementKey(q, e, i);
167+
}
168+
169+
void PQ_adjustKey(PriorityQueue * const q, int val, double i)
170+
{
171+
QueueElement * e = q->elements[val];
172+
if(e != NULL)
173+
PQ_adjustElementKey(q, e, i);
174+
}
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)