forked from open-mpi/ompi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request open-mpi#4014 from bosilca/topic/treematch
Topic/treematch
- Loading branch information
Showing
38 changed files
with
5,416 additions
and
3,063 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
717 changes: 335 additions & 382 deletions
717
ompi/mca/topo/treematch/topo_treematch_dist_graph_create.c
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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*/ |
Oops, something went wrong.