Skip to content

Commit bd85ab2

Browse files
committed
Version 1.0
0 parents  commit bd85ab2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+25766
-0
lines changed

MPI_Implementation/ExactMP

484 KB
Binary file not shown.

MPI_Implementation/Makefile

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
CFLAGS = -O3 -fomit-frame-pointer -fkeep-inline-functions -finline-limit=50000 -fforce-addr -funroll-loops -frerun-cse-after-loop -frerun-loop-opt -falign-functions=4 -c
2+
CLIBS =
3+
GCC = ~/MPI/bin/mpicc
4+
all: ExactMP
5+
6+
#run: ~/mpich/bin/mpirun $(NUMPROC) $(PROC) $(BINFILE) $(DATAFILE)
7+
8+
ExactMP: main.o preProc.o uTaskGen.o uCompCost.o uDataStr.o addOrder.o frameWork.o uBnB.o aggGreedy.o uPLB.o tbr.o eckDay.o nj.o randOpt.o oBnB.o oDataStr.o oPLB.o oTaskGen.o oDispTree.o opBnB.o
9+
$(GCC) main.o preProc.o uTaskGen.o uCompCost.o uDataStr.o addOrder.o frameWork.o uBnB.o aggGreedy.o uPLB.o tbr.o eckDay.o randOpt.o nj.o oBnB.o oDataStr.o oPLB.o oTaskGen.o opBnB.o oDispTree.o -lm -o ExactMP
10+
rm -rf *.o
11+
12+
main.o: main.c
13+
$(GCC) $(CFLAGS) main.c $(CLIBS) -o main.o
14+
15+
preProc.o: preProc.c
16+
$(GCC) $(CFLAGS) preProc.c $(CLIBS) -o preProc.o
17+
18+
uTaskGen.o: uTaskGen.c
19+
$(GCC) $(CFLAGS) uTaskGen.c $(CLIBS) -o uTaskGen.o
20+
21+
uCompCost.o: uCompCost.c
22+
$(GCC) $(CFLAGS) uCompCost.c $(CLIBS) -o uCompCost.o
23+
24+
uDataStr.o: uDataStr.c
25+
$(GCC) $(CFLAGS) uDataStr.c $(CLIBS) -o uDataStr.o
26+
27+
addOrder.o: addOrder.c
28+
$(GCC) $(CFLAGS) addOrder.c $(CLIBS) -o addOrder.o
29+
30+
frameWork.o: frameWork.c
31+
$(GCC) $(CFLAGS) frameWork.c $(CLIBS) -o frameWork.o
32+
33+
uBnB.o: uBnB.c
34+
$(GCC) $(CFLAGS) uBnB.c $(CLIBS) -o uBnB.o
35+
36+
aggGreedy.o: aggGreedy.c
37+
$(GCC) $(CFLAGS) aggGreedy.c $(CLIBS) -o aggGreedy.o
38+
39+
uPLB.o: uPLB.c
40+
$(GCC) $(CFLAGS) uPLB.c $(CLIBS) -o uPLB.o
41+
42+
tbr.o: tbr.c
43+
$(GCC) $(CFLAGS) tbr.c $(CLIBS) -o tbr.o
44+
45+
eckDay.o: eckDay.c
46+
$(GCC) $(CFLAGS) eckDay.c $(CLIBS) -o eckDay.o
47+
48+
nj.o: nj.c
49+
$(GCC) $(CFLAGS) nj.c $(CLIBS) -o nj.o
50+
51+
randOpt.o: randOpt.c
52+
$(GCC) $(CFLAGS) randOpt.c $(CLIBS) -o randOpt.o
53+
54+
oTaskGen.o: oTaskGen.c
55+
$(GCC) $(CFLAGS) oTaskGen.c $(CLIBS) -o oTaskGen.o
56+
57+
oBnB.o: oBnB.c
58+
$(GCC) $(CFLAGS) oBnB.c $(CLIBS) -o oBnB.o
59+
60+
oPLB.o: oPLB.c
61+
$(GCC) $(CFLAGS) oPLB.c $(CLIBS) -o oPLB.o
62+
63+
oDataStr.o: oDataStr.c
64+
$(GCC) $(CFLAGS) oDataStr.c $(CLIBS) -o oDataStr.o
65+
66+
oDispTree.o: oDispTree.c
67+
$(GCC) $(CFLAGS) oDispTree.c $(CLIBS) -o oDispTree.o
68+
69+
opBnB.o: opBnB.c
70+
$(GCC) $(CFLAGS) opBnB.c $(CLIBS) -o opBnB.o
71+
72+
clean:
73+
rm -rf *.o ExactMP

MPI_Implementation/addOrder.c

+286
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
/*************************************************************************************************************************
2+
* DESCRIPTION: This function generates the taxa addition order using max mini algorithm. *
3+
* *
4+
* INPUTS: None *
5+
* *
6+
* OUTPUTS: Queue containing the addition order of taxa, writes directly into global queue. Doesnt return anything *
7+
************************************************************************************************************************/
8+
#include "header.h"
9+
10+
void taxaAddOrder(void) {
11+
int taxaOver = 3;
12+
struct subTask *sourceTree, *childTree;
13+
struct maxMiniTaxaPosWLength mMTPWL;
14+
struct taxaQ *t;
15+
16+
sourceTree = genIstSubTask();
17+
/* enqueue all taxa to be checked for addition order */
18+
/* this will be from 4 to NUMBER of TAXA */
19+
enqueueTaxa();
20+
/* apply maxmini, & enqueue first addition order taxa */
21+
mMTPWL = maxMini(sourceTree);
22+
enqueueAddOrdTaxa(mMTPWL.taxa);
23+
taxaOver += 1;
24+
/* for all taxa remaining to be enqueued in addition order */
25+
while (taxaOver < matrix.num_taxa) {
26+
#ifdef TAXA_ADD_ORDER_VERBOSE
27+
printf("\t\t\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~\n");
28+
printf("\t\t\t\t\t\tADDING NEXT TAXA ORDER\n");
29+
printf("\t\t\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~");
30+
#endif
31+
/* generate next task with previous maxmini taxa, position */
32+
childTree = genNextTask(sourceTree, childTree, mMTPWL.taxa, mMTPWL.pos);
33+
/* free parent task, it is not needed anymode */
34+
freeTree(sourceTree);
35+
sourceTree = childTree;
36+
#ifdef TAXA_ADD_ORDER_VERBOSE
37+
printTree(sourceTree,mMTPWL.pos);
38+
#endif
39+
/* apply maxmini, & enqueue next addition order taxa */
40+
mMTPWL = maxMini(sourceTree);
41+
enqueueAddOrdTaxa(mMTPWL.taxa);
42+
taxaOver += 1;
43+
}
44+
/* if the final tree cost is less than best cost computed */
45+
/* by SG algorithm, set this as best cost */
46+
if (mMTPWL.length < bestCost) {
47+
bestCost = mMTPWL.length;
48+
flushBestCostStack();
49+
childTree = genNextTask(sourceTree, childTree, mMTPWL.taxa, mMTPWL.pos);
50+
freeTree(sourceTree);
51+
pushBestCostNode(childTree);
52+
}
53+
else {
54+
freeTree(sourceTree);
55+
}
56+
57+
//printf("\t\t\t[BEST SCORE %d]\n",bestCost+pNiCost);
58+
//fprintf(fp,"\t\t\t[BEST SCORE %d]\n",bestCost+pNiCost);
59+
60+
//printf("\tTaxa addition order: 1 2 3 ");
61+
//fprintf(fp,"\tTaxa addition order: 1 2 3 ");
62+
taxaQueue[0] = 1;
63+
taxaQueue[1] = 2;
64+
taxaQueue[2] = 3;
65+
for (taxaOver=3, t=tAddOrdQHead; t != NULL; t = t->next, taxaOver=taxaOver+1) {
66+
taxaQueue[taxaOver] = t->taxa;
67+
//printf("%d ",t->taxa);
68+
//fprintf(fp,"%d ",t->taxa);
69+
}
70+
//printf("\n");
71+
//fprintf(fp,"\n");
72+
73+
}
74+
75+
/*************************************************************************************************************************
76+
* DESCRIPTION: This function implements maxmini algorithm *
77+
* *
78+
* INPUTS: Sub task on which to apply maxmini algorithm *
79+
* *
80+
* OUTPUTS: structure containing the taxon to be added next, position where it is to be added and tree lenght *
81+
************************************************************************************************************************/
82+
struct maxMiniTaxaPosWLength maxMini(struct subTask *sourceTree) {
83+
struct maxMiniTaxaPosWLength prevmMTPWL, currmMTPWL;
84+
struct taxaQ *tQNode;
85+
86+
int taxaNum;
87+
88+
prevmMTPWL.length = 0;
89+
prevmMTPWL.taxa = 0;
90+
prevmMTPWL.pos = 0;
91+
currmMTPWL.length = 0;
92+
currmMTPWL.taxa = 0;
93+
currmMTPWL.pos = 0;
94+
95+
#ifdef MAX_MINI_VERBOSE
96+
printf("\n\t\t*************************************************************************************************\n");
97+
printf("\n\t\t\t\t\t\t\tMAXMINI FUNCTION\n");
98+
printf("\n\t\t*************************************************************************************************\n");
99+
#endif
100+
/* for all taxa remaining to be added */
101+
for (tQNode = taxaQHead; tQNode != NULL; tQNode=tQNode->next) {
102+
taxaNum = tQNode->taxa;
103+
/* get tree with minimum length with this taxa added to the */
104+
/* subtask under view (check for all positions) */
105+
#ifdef MAXMINI
106+
currmMTPWL = getMinTree(sourceTree, taxaNum);
107+
#endif
108+
#ifdef MAXMAX
109+
currmMTPWL = getMaxTree(sourceTree, taxaNum);
110+
#endif
111+
#ifdef MAX_MINI_VERBOSE
112+
printf("\n\t\t->->->->->->RETAIN MAXIMUM LENGTH OF ALL MINIMUM LENGTHS<-<-<-<-<-<-\n");
113+
printf("\t\tCurr {MinLen:%3d @ Pos:%3d w/ Taxa:%3d} vs. Prev {MinLen:%3d @ Pos:%3d w/ Taxa:%3d}\n",currmMTPWL.length, currmMTPWL.pos, currmMTPWL.taxa, prevmMTPWL.length, prevmMTPWL.pos, prevmMTPWL.taxa);
114+
#endif
115+
/* this length > previous length, this is maximum, keep it */
116+
if (currmMTPWL.length > prevmMTPWL.length) {
117+
#ifdef MAX_MINI_VERBOSE
118+
printf("\t\tCurr Min Lgt (%d) > Prev Min Lgt (%d)=> ",currmMTPWL.length,prevmMTPWL.length);
119+
#endif
120+
prevmMTPWL.pos = currmMTPWL.pos;
121+
prevmMTPWL.taxa = currmMTPWL.taxa;
122+
prevmMTPWL.length = currmMTPWL.length;
123+
#ifdef MAX_MINI_VERBOSE
124+
printf("Update Curr Max Len to {MaxLen:%3d @ Pos:%3d w/ Taxa:%3d}\n", prevmMTPWL.length, prevmMTPWL.pos, prevmMTPWL.taxa);
125+
#endif
126+
}
127+
}
128+
/* remove taxa added to taxa addition order */
129+
deleteTaxa(prevmMTPWL.taxa);
130+
131+
return (prevmMTPWL);
132+
}
133+
134+
/**************************************************************************************************************************
135+
* DESCRIPTION: This function returns the tree with minimum length, with the position where a given taxa should be added *
136+
* This checks the given taxa at all positions and returns the minimum tree. If there is a tie, it just picks*
137+
* up the first one and ignores the rest *
138+
* *
139+
* INPUTS: Sub task on which to apply maxmini algorithm, and taxa which is to be added *
140+
* *
141+
* OUTPUTS: Structure containing the taxon to be added next, position where it is to be added and tree length *
142+
*************************************************************************************************************************/
143+
struct maxMiniTaxaPosWLength getMinTree(struct subTask *sourceTree, int taxaNum) {
144+
struct subTask *childTree;
145+
int currentLength = 0;
146+
int prevLength = 0;
147+
148+
struct maxMiniTaxaPosWLength mMTPWL;
149+
150+
int pos;
151+
int currMinPos;
152+
int currMinTaxa;
153+
int arraySize = sourceTree->sizeOfSubTaskArray;
154+
155+
#ifdef GET_MIN_TREE_VERBOSE
156+
printf("\n\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
157+
printf("\t\t\t\t CHECKING MINIMUM TREE LENGTH FOR ALL POSITIONS FOR TAXA: %d\n",taxaNum);
158+
printf("\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
159+
#endif
160+
/* generate first case, adding taxa in position 0 */
161+
childTree = genNextTask(sourceTree, childTree, taxaNum, 0);
162+
#ifdef GET_MIN_TREE_VERBOSE
163+
printTree(childTree, 0);
164+
#endif
165+
/* update initial tree length to the length in position 0 */
166+
prevLength = childTree->costOfSubTask;
167+
freeTree(childTree);
168+
169+
currMinPos = 0;
170+
currMinTaxa = taxaNum;
171+
172+
/* for all remaining positions */
173+
for (pos=1; pos < arraySize; pos++) {
174+
/* do not try position before internal node -1 */
175+
/* this is done to ensure that the integrity of tree */
176+
if (sourceTree->node[pos].id != -1) {
177+
childTree = genNextTask(sourceTree,childTree, taxaNum, pos);
178+
#ifdef GET_MIN_TREE_VERBOSE
179+
printTree(childTree, pos);
180+
#endif
181+
currentLength = childTree->costOfSubTask;
182+
#ifdef GET_MIN_TREE_VERBOSE
183+
printf("\n\t\t->->->->->->RETAIN MINIMUM LENGTH FROM CURRENT & PREVIOUS LENGTHS<-<-<-<-<-<-\n");
184+
printf("\n\t\t\tCurr {MinLen:%3d @ Pos:%3d w/ Taxa:%3d} vs. Prev {MinLen:%3d @ Pos:%3d w/ Taxa:%3d}\n\n",currentLength, pos, taxaNum, prevLength, currMinPos, currMinTaxa);
185+
#endif
186+
/* if this length is less than previous length, keep it */
187+
if (currentLength < prevLength) {
188+
#ifdef GET_MIN_TREE_VERBOSE
189+
printf("\t\tCurr Lgt (%d) < Prev Lgt (%d)=> ",currentLength,prevLength);
190+
#endif
191+
prevLength = currentLength;
192+
currMinPos = pos;
193+
currMinTaxa = taxaNum;
194+
#ifdef GET_MIN_TREE_VERBOSE
195+
printf("Update Curr Lgt to: %d & keeping Taxa: %d, Pos: %d\n\n",currentLength,currMinTaxa,currMinPos);
196+
#endif
197+
}
198+
199+
freeTree(childTree);
200+
}
201+
}
202+
203+
/* return position & tree with minimum length */
204+
mMTPWL.taxa = currMinTaxa;
205+
mMTPWL.pos = currMinPos;
206+
mMTPWL.length = prevLength;
207+
208+
return (mMTPWL);
209+
}
210+
211+
/**************************************************************************************************************************
212+
* DESCRIPTION: This function returns the tree with maximum length, with the position where a given taxa should be added *
213+
* This checks the given taxa at all positions and returns the maximum tree. If there is a tie, it just picks*
214+
* up the first one and ignores the rest *
215+
* *
216+
* INPUTS: Sub task on which to apply maxmax algorithm, and taxa which is to be added *
217+
* *
218+
* OUTPUTS: Structure containing the taxon to be added next, position where it is to be added and tree length *
219+
*************************************************************************************************************************/
220+
struct maxMiniTaxaPosWLength getMaxTree(struct subTask *sourceTree, int taxaNum) {
221+
struct subTask *childTree;
222+
int currentLength = 0;
223+
int prevLength = 0;
224+
225+
struct maxMiniTaxaPosWLength mMTPWL;
226+
227+
int pos;
228+
int currMinPos;
229+
int currMinTaxa;
230+
int arraySize = sourceTree->sizeOfSubTaskArray;
231+
232+
#ifdef GET_MIN_TREE_VERBOSE
233+
printf("\n\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
234+
printf("\t\t\t\t CHECKING MINIMUM TREE LENGTH FOR ALL POSITIONS FOR TAXA: %d\n",taxaNum);
235+
printf("\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
236+
#endif
237+
/* generate first case, adding taxa in position 0 */
238+
childTree = genNextTask(sourceTree, childTree, taxaNum, 0);
239+
#ifdef GET_MIN_TREE_VERBOSE
240+
printTree(childTree, 0);
241+
#endif
242+
/* update initial tree length to the length in position 0 */
243+
prevLength = childTree->costOfSubTask;
244+
freeTree(childTree);
245+
246+
currMinPos = 0;
247+
currMinTaxa = taxaNum;
248+
249+
/* for all remaining positions */
250+
for (pos=1; pos < arraySize; pos++) {
251+
/* do not try position before internal node -1 */
252+
/* this is done to ensure that the integrity of tree */
253+
if (sourceTree->node[pos].id != -1) {
254+
childTree = genNextTask(sourceTree,childTree, taxaNum, pos);
255+
#ifdef GET_MIN_TREE_VERBOSE
256+
printTree(childTree, pos);
257+
#endif
258+
currentLength = childTree->costOfSubTask;
259+
#ifdef GET_MIN_TREE_VERBOSE
260+
printf("\n\t\t->->->->->->RETAIN MAXIMUM LENGTH FROM CURRENT & PREVIOUS LENGTHS<-<-<-<-<-<-\n");
261+
printf("\n\t\t\tCurr {MinLen:%3d @ Pos:%3d w/ Taxa:%3d} vs. Prev {MinLen:%3d @ Pos:%3d w/ Taxa:%3d}\n\n",currentLength, pos, taxaNum, prevLength, currMinPos, currMinTaxa);
262+
#endif
263+
/* if this length is more than previous length, keep it */
264+
if (currentLength > prevLength) {
265+
#ifdef GET_MIN_TREE_VERBOSE
266+
printf("\t\tCurr Lgt (%d) > Prev Lgt (%d)=> ",currentLength,prevLength);
267+
#endif
268+
prevLength = currentLength;
269+
currMinPos = pos;
270+
currMinTaxa = taxaNum;
271+
#ifdef GET_MIN_TREE_VERBOSE
272+
printf("Update Curr Lgt to: %d & keeping Taxa: %d, Pos: %d\n\n",currentLength,currMinTaxa,currMinPos);
273+
#endif
274+
}
275+
276+
freeTree(childTree);
277+
}
278+
}
279+
280+
/* return position & tree with minimum length */
281+
mMTPWL.taxa = currMinTaxa;
282+
mMTPWL.pos = currMinPos;
283+
mMTPWL.length = prevLength;
284+
285+
return (mMTPWL);
286+
}

0 commit comments

Comments
 (0)