-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be0e540
commit 93ed83a
Showing
9 changed files
with
209 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
!.gitignore | ||
|
||
# Extensions, misc | ||
.DS_Store | ||
*.DS_Store | ||
*.e | ||
*.o | ||
*.dSYM |
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 |
---|---|---|
|
@@ -15,6 +15,6 @@ | |
#define SHIFTBITS 31 | ||
#define LONGBITS 63 | ||
|
||
#define COMMBUF_SIZE 64 | ||
#define COMMBUF_SIZE 1280 | ||
|
||
#endif |
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,95 @@ | ||
#include <chrono> | ||
#include <iostream> | ||
|
||
// TODO | ||
// tune openMP to handle horizontal better? | ||
|
||
int main(int argc, char** argv) { | ||
if (argc != 3) { | ||
printf("error: incorrect number of arguments (expected 2, got %i)\n", | ||
argc - 1); | ||
return 1; | ||
} | ||
|
||
MPI_Init(NULL, NULL); | ||
int nProc, rank; | ||
MPI_Comm_size(MPI_COMM_WORLD, &nProc); | ||
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | ||
|
||
dnaArray s1, s2; | ||
try { | ||
s1 = readSequence(argv[1]); | ||
s2 = readSequence(argv[2]); | ||
} | ||
|
||
catch (std::string e) { | ||
std::cout << "ERROR: no such file " << e << std::endl; | ||
printf("ERROR: file not found\n"); | ||
return 1; | ||
} | ||
|
||
long int nRows = ((s2.size + 1) / nProc) + (rank > 0); | ||
if (rank == nProc - 1) { nRows += (s2.size + 1) % nProc; } | ||
|
||
long int size = nRows * (long int)(s1.size + 1); | ||
int* table = new int[size]; | ||
for (long int i = 0; i < size; i += 1024) { table[i] = 0; } | ||
|
||
// get start time in ms since epoch | ||
long int wallStart = std::chrono::duration_cast<std::chrono::milliseconds>( | ||
std::chrono::system_clock::now().time_since_epoch()).count(); | ||
|
||
// print start time | ||
// printf("P%i | wallStart: %li\n", rank, wallStart); | ||
|
||
// run the algorithm | ||
needlemanWunsch(s1, s2, nRows, rank, nProc, table); | ||
|
||
// get end time in ms since epoch | ||
long int wallEnd = std::chrono::duration_cast<std::chrono::milliseconds>( | ||
std::chrono::system_clock::now().time_since_epoch()).count(); | ||
|
||
// print end time | ||
// printf("P%i | wallEnd: %li\n", rank, wallEnd); | ||
|
||
MPI_Barrier(MPI_COMM_WORLD); | ||
|
||
|
||
// collect and display time info on rank 0 | ||
if (rank == 0) { | ||
// first process to start--used as start for timer | ||
long int first = wallStart; | ||
|
||
// collect start times, get minimum | ||
long int recStart, recEnd; | ||
for (int i = 1; i < nProc; ++i) { | ||
MPI_Recv(&recStart, 1, MPI_LONG, i, i, MPI_COMM_WORLD, NULL); | ||
first = (recStart < first) ? recStart: first; | ||
} | ||
|
||
// get last time (guaranteed to be last process by data deps) | ||
MPI_Recv(&recEnd, nProc-1, MPI_LONG, nProc-1, nProc-1, | ||
MPI_COMM_WORLD, NULL); | ||
|
||
printf("time: %li\n", recEnd - first); | ||
} | ||
|
||
// send time info to rank 0 | ||
else { | ||
MPI_Send(&wallStart, 1, MPI_LONG, 0, rank, MPI_COMM_WORLD); | ||
} | ||
if (rank == nProc - 1) { | ||
MPI_Send(&wallEnd, 1, MPI_LONG, 0, rank, MPI_COMM_WORLD); | ||
} | ||
|
||
MPI_Barrier(MPI_COMM_WORLD); | ||
|
||
// display final score | ||
if (rank == nProc - 1) { | ||
printf("final score: %i\n", table[size-1]); | ||
} | ||
|
||
MPI_Finalize(); | ||
|
||
return 0; | ||
} |
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,101 @@ | ||
#include "nw-mpi.hpp" | ||
|
||
// takes in the array to be filled--don't care about the allocation time | ||
void needlemanWunsch(dnaArray s1, dnaArray s2, long int nRows, | ||
int rank, int nProc, int* t) { | ||
// note: s1 across top, s2 down side | ||
|
||
// convenience | ||
long int nCols = s1.size + 1; | ||
int a, b, c, m; // temps for max calculation | ||
|
||
// necessary for Isend | ||
// MPI_Request* dummy = new MPI_Request; | ||
|
||
// first index of s2 in this table (last index of rank-1's work) | ||
long int start = ((s2.size + 1) / nProc) * rank - (rank > 0); | ||
|
||
// populate first column | ||
for (long int i = 0; i < nRows; ++i) { t[i*nCols] = (i + start) * GAP; } | ||
|
||
// RANK 0 | ||
// never receives; only sends to rank 1 | ||
if (rank == 0) { | ||
// populate first row | ||
for (long int i = 0; i < nCols; ++i) { t[i] = i * GAP; } | ||
|
||
for (long int h = 1; h < nCols; h += COMMBUF_SIZE) { | ||
long int jMax = (h + COMMBUF_SIZE < nCols) ? h + COMMBUF_SIZE : nCols; | ||
for (long int i = 1; i < nRows; ++i) { | ||
for (long int j = h; j < jMax; ++j) { | ||
m = -(s1.dna[j-1] == s2.dna[start+i-1]); | ||
a = t[((i-1) * nCols) + j-1] + ((m & MATCH) | (~m & MISMATCH)); | ||
b = t[((i-1) * nCols) + j] + GAP; | ||
c = t[(i * nCols) + j-1] + GAP; | ||
|
||
a = a - (((a - b) >> SHIFTBITS) & (a - b)); | ||
a = a - (((a - c) >> SHIFTBITS) & (a - c)); | ||
t[(i * nCols) + j] = a; | ||
} | ||
} | ||
MPI_Send(&t[(nRows-1)*nCols+h], jMax - h, MPI_INT, 1, 0, | ||
MPI_COMM_WORLD); | ||
} | ||
} | ||
|
||
// RANK N-1 | ||
// never sends; only receives from rank-1 | ||
else if (rank == nProc - 1) { | ||
for (long int h = 1; h < nCols; h += COMMBUF_SIZE) { | ||
long int jMax = (h + COMMBUF_SIZE < nCols) ? h + COMMBUF_SIZE : nCols; | ||
|
||
// receive into first row | ||
MPI_Recv(&t[h], jMax - h, MPI_INT, rank-1, rank-1, | ||
MPI_COMM_WORLD, NULL); | ||
|
||
for (long int i = 1; i < nRows; ++i) { | ||
for (long int j = h; j < jMax; ++j) { | ||
m = -(s1.dna[j-1] == s2.dna[start+i-1]); | ||
a = t[((i-1) * nCols) + j-1] + ((m & MATCH) | (~m & MISMATCH)); | ||
b = t[((i-1) * nCols) + j] + GAP; | ||
c = t[(i * nCols) + j-1] + GAP; | ||
|
||
a = a - (((a - b) >> SHIFTBITS) & (a - b)); | ||
a = a - (((a - c) >> SHIFTBITS) & (a - c)); | ||
t[(i * nCols) + j] = a; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// ALL OTHER RANKS | ||
// receive at the start, then send | ||
else { | ||
for (long int h = 1; h < nCols; h += COMMBUF_SIZE) { | ||
long int jMax = (h + COMMBUF_SIZE < nCols) ? h + COMMBUF_SIZE : nCols; | ||
|
||
// receive into first row | ||
MPI_Recv(&t[h], COMMBUF_SIZE, MPI_INT, rank-1, rank-1, | ||
MPI_COMM_WORLD, NULL); | ||
|
||
for (long int i = 1; i < nRows; ++i) { | ||
for (long int j = h; j < jMax; ++j) { | ||
m = -(s1.dna[j-1] == s2.dna[start+i-1]); | ||
a = t[((i-1) * nCols) + j-1] + ((m & MATCH) | (~m & MISMATCH)); | ||
b = t[((i-1) * nCols) + j] + GAP; | ||
c = t[(i * nCols) + j-1] + GAP; | ||
|
||
a = a - (((a - b) >> SHIFTBITS) & (a - b)); | ||
a = a - (((a - c) >> SHIFTBITS) & (a - c)); | ||
t[(i * nCols) + j] = a; | ||
} | ||
} | ||
MPI_Send(&t[(nRows-1)*nCols+h], jMax-h, MPI_INT, rank+1, | ||
rank, MPI_COMM_WORLD); | ||
} | ||
} | ||
|
||
return; | ||
} | ||
|
||
#include "mpi-horz-driver.cpp" |
File renamed without changes.
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 @@ | ||
../../bdna |
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