Skip to content
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
17 changes: 11 additions & 6 deletions ompi/mca/topo/treematch/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@

if topo_treematch_local
extra_treematch_files = treematch/tm_bucket.h \
treematch/tm_hwloc.h treematch/tm_mapping.h \
treematch/tm_mapping.h \
treematch/tm_timings.h treematch/tm_tree.h \
treematch/tm_kpartitioning.h treematch/uthash.h\
treematch/IntConstantInitializedVector.h \
treematch/tm_mt.h \
treematch/tm_mt.h treematch/fibo.h \
treematch/tm_thread_pool.h treematch/tm_verbose.h \
treematch/tm_malloc.h \
treematch/tm_malloc.h treematch/k-partitioning.h\
treematch/tm_solution.h treematch/tm_topology.h\
treematch/PriorityQueue.h \
treematch/IntConstantInitializedVector.c \
treematch/tm_mt.c \
treematch/tm_mt.c treematch/fibo.c \
treematch/tm_thread_pool.c treematch/tm_verbose.c \
treematch/tm_malloc.c \
treematch/tm_malloc.c treematch/treematch.h \
treematch/tm_mapping.c treematch/tm_timings.c \
treematch/tm_bucket.c treematch/tm_tree.c \
treematch/tm_hwloc.c treematch/tm_kpartitioning.c
treematch/tm_topology.c treematch/tm_kpartitioning.c \
treematch/tm_solution.c treematch/k-partitioning.c \
treematch/PriorityQueue.c
EXTRA_DIST = treematch/COPYING treematch/LICENSE
endif

sources = \
Expand Down
7 changes: 7 additions & 0 deletions ompi/mca/topo/treematch/topo_treematch_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ mca_topo_treematch_component_2_2_0_t mca_topo_treematch_component =

static int init_query(bool enable_progress_threads, bool enable_mpi_threads)
{
if (OPAL_SUCCESS != opal_hwloc_base_get_topology()) {
return OPAL_ERR_NOT_SUPPORTED;
}
if(NULL == opal_hwloc_topology) {
return OPAL_ERR_NOT_SUPPORTED;
}
return OMPI_SUCCESS;
}

Expand Down Expand Up @@ -95,3 +101,4 @@ static int mca_topo_treematch_component_register(void)
MCA_BASE_VAR_SCOPE_READONLY, &mca_topo_treematch_component.reorder_mode);
return OMPI_SUCCESS;
}

719 changes: 334 additions & 385 deletions ompi/mca/topo/treematch/topo_treematch_dist_graph_create.c

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
#include <stdio.h>
#include "IntConstantInitializedVector.h"


int intCIV_isInitialized(int_CIVector * v, int i)
{
if(v->top == 0)
return 0;
if(v->from[i] >= 0)
if(v->from[i] < v->top && v->to[v->from[i]] == i)
if(v->from[i] < v->top && v->to[v->from[i]] == i)
return 1;
return 0;
}
Expand Down Expand Up @@ -45,7 +44,7 @@ int intCIV_set(int_CIVector * v, int i, int val)
v->top++;
}
v->vec[i] = val;
return 0;
return 0;
}

int intCIV_get(int_CIVector * v, int i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ void intCIV_exit(int_CIVector * v);
int intCIV_set(int_CIVector * v, int i, int val);
int intCIV_get(int_CIVector * v, int i);


#endif /*INTEGER_CONSTANT_INITIALIZED_VECTOR*/
170 changes: 170 additions & 0 deletions ompi/mca/topo/treematch/treematch/PriorityQueue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#include <stdlib.h>
#include "PriorityQueue.h"

/*
This comparison function is used to sort elements in key descending order.
*/
static int compFunc(const FiboNode * const node1, const FiboNode * const node2)
{
return
( ( ((QueueElement*)(node1))->key > ((QueueElement*)(node2))->key ) ? -1 : 1);
}

int PQ_init(PriorityQueue * const q, int size)
{
int i;
q->size = size;
q->elements = malloc(sizeof(QueueElement *) * size);
for(i=0; i < size; i++)
q->elements[i]=NULL;
return fiboTreeInit((FiboTree *)q, compFunc);
}

void PQ_exit(PriorityQueue * const q)
{

int i;
for(i = 0; i < q->size; i++)
{
if(q->elements[i] != NULL)
free(q->elements[i]);
}
if(q->elements != NULL)
free(q->elements);
fiboTreeExit((FiboTree *)q);
}
void PQ_free(PriorityQueue * const q)
{
int i;
for(i = 0; i < q->size; i++)
{
if(q->elements[i] != NULL)
free(q->elements[i]);
}
fiboTreeFree((FiboTree *)q);
}

int PQ_isEmpty(PriorityQueue * const q)
{
FiboTree * tree = (FiboTree *)q;
/* if the tree root is linked to itself then the tree is empty */
if(&(tree->rootdat) == (tree->rootdat.linkdat.nextptr))
return 1;
return 0;
}

void PQ_insertElement(PriorityQueue * const q, QueueElement * const e)
{
if(e->value >= 0 && e->value < q->size)
{
fiboTreeAdd((FiboTree *)q, (FiboNode *)(e));
q->elements[e->value] = e;
e->isInQueue = 1;
}
}
void PQ_deleteElement(PriorityQueue * const q, QueueElement * const e)
{
fiboTreeDel((FiboTree *)q, (FiboNode *)(e));
q->elements[e->value] = NULL;
e->isInQueue = 0;
}

void PQ_insert(PriorityQueue * const q, int val, double key)
{
if( val >= 0 && val < q->size)
{
QueueElement * e = malloc(sizeof(QueueElement));
e->value = val;
e->key = key;
PQ_insertElement(q, e);
}
}

void PQ_delete(PriorityQueue * const q, int val)
{
QueueElement * e = q->elements[val];
PQ_deleteElement(q, e);
free(e);
}

QueueElement * PQ_findMaxElement(PriorityQueue * const q)
{
QueueElement * e = (QueueElement *)(fiboTreeMin((FiboTree *)q));
return e;
}
QueueElement * PQ_deleteMaxElement(PriorityQueue * const q)
{
QueueElement * e = (QueueElement *)(fiboTreeMin((FiboTree *)q));
if(e != NULL)
{
PQ_deleteElement(q, e);
}
return e;
}

double PQ_findMaxKey(PriorityQueue * const q)
{
QueueElement * e = PQ_findMaxElement(q);
if(e!=NULL)
return e->key;
return 0;
}

int PQ_deleteMax(PriorityQueue * const q)
{
QueueElement * e = PQ_deleteMaxElement(q);
int res = -1;
if(e != NULL)
res = e->value;
free(e);
return res;
}

void PQ_increaseElementKey(PriorityQueue * const q, QueueElement * const e, double i)
{
if(e->isInQueue)
{
PQ_deleteElement(q, e);
e->key += i;
PQ_insertElement(q, e);
}
}
void PQ_decreaseElementKey(PriorityQueue * const q, QueueElement * const e, double i)
{
if(e->isInQueue)
{
PQ_deleteElement(q, e);
e->key -= i;
PQ_insertElement(q, e);
}
}
void PQ_adjustElementKey(PriorityQueue * const q, QueueElement * const e, double i)
{
if(e->isInQueue)
{
PQ_deleteElement(q, e);
e->key = i;
PQ_insertElement(q, e);
}
}

void PQ_increaseKey(PriorityQueue * const q, int val, double i)
{
QueueElement * e = q->elements[val];
if(e != NULL)
PQ_increaseElementKey(q, e, i);
}

void PQ_decreaseKey(PriorityQueue * const q, int val, double i)
{
QueueElement * e = q->elements[val];
if(e != NULL)
PQ_decreaseElementKey(q, e, i);
}

void PQ_adjustKey(PriorityQueue * const q, int val, double i)
{
QueueElement * e = q->elements[val];
if(e != NULL)
PQ_adjustElementKey(q, e, i);
}
108 changes: 108 additions & 0 deletions ompi/mca/topo/treematch/treematch/PriorityQueue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#ifndef PRIORITY_QUEUE
#define PRIORITY_QUEUE

#include "fibo.h"

/*
This is the struct for our elements in a PriorityQueue.
The node is at first place so we only have to use a cast to switch between QueueElement's pointer and Fibonode's pointer.
*/
typedef struct QueueElement_
{
FiboNode node; /*the node used to insert the element in a FiboTree*/
double key; /*the key of the element, elements are sorted in a descending order according to their key*/
int value;
int isInQueue;
} QueueElement;

typedef struct PriorityQueue_
{
FiboTree tree;
QueueElement ** elements; /*a vector of element with their value as key so we can easily retreive an element from its value */
int size; /*the size allocated to the elements vector*/
} PriorityQueue;


/*
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.
Returns :
0 if success
!0 if failed

PQ_free simply empties the PriorityQueue but does not free the memory used by its elements.
PQ_exit destroys the PriorityQueue without freeing elements. The PriorityQueue is no longer usable without using PQ_init again.
Note that the PriorityQueue pointer is not deallocated.
*/
int PQ_init(PriorityQueue * const, int size);
void PQ_free(PriorityQueue * const);
void PQ_exit(PriorityQueue * const);

/*
PQ_isEmpty returns 1 if the PriorityQueue is empty, 0 otherwise.
*/
int PQ_isEmpty(PriorityQueue * const);

/*
PQ_insertElement inserts the given QueueElement in the given PriorityQueue
*/
void PQ_insertElement(PriorityQueue * const, QueueElement * const);
/*
PQ_deleteElement delete the element given in argument from the PriorityQueue.
*/
void PQ_deleteElement(PriorityQueue * const, QueueElement * const);

/*
PQ_insert inserts an element in the PriorityQueue with the value and key given in argument.
*/
void PQ_insert(PriorityQueue * const, int val, double key);
/*
PQ_delete removes the first element found with the value given in argument and frees it.
*/
void PQ_delete(PriorityQueue * const, int val);


/*
PQ_findMaxElement returns the QueueElement with the greatest key in the given PriorityQueue
*/
QueueElement * PQ_findMaxElement(PriorityQueue * const);
/*
PQ_deleteMaxElement returns the QueueElement with the geatest key in the given PriorityQueue and removes it from the queue.
*/
QueueElement * PQ_deleteMaxElement(PriorityQueue * const);

/*
PQ_findMax returns the key of the element with the geatest key in the given PriorityQueue
*/
double PQ_findMaxKey(PriorityQueue * const);
/*
PQ_deleteMax returns the value of the element with the greatest key in the given PriorityQueue and removes it from the queue.
*/
int PQ_deleteMax(PriorityQueue * const);

/*
PQ_increaseElementKey adds the value of i to the key of the given QueueElement
*/
void PQ_increaseElementKey(PriorityQueue * const, QueueElement * const, double i);
/*
PQ_decreaseElementKey substracts the value of i from the key of the given QueueElement
*/
void PQ_decreaseElementKey(PriorityQueue * const, QueueElement * const, double i);
/*
PQ_adjustElementKey sets to i the key of the given QueueElement.
*/
void PQ_adjustElementKey(PriorityQueue * const, QueueElement * const, double i);

/*
PQ_increaseKey adds i to the key of the first element found with a value equal to val in the PriorityQueue.
*/
void PQ_increaseKey(PriorityQueue * const, int val, double i);
/*
PQ_decreaseKey substracts i from the key of the first element found with a value equal to val in the PriorityQueue.
*/
void PQ_decreaseKey(PriorityQueue * const, int val, double i);
/*
PQ_adjustKey sets to i the key of the first element found with a value equal to val in the PriorityQueue.
*/
void PQ_adjustKey(PriorityQueue * const, int val, double i);

#endif /*PRIORITY_QUEUE*/
Loading