72 #define BEGIN(coord,dims,size) (coord * size / dims)
77 #define END(coord,dims,size) ((( coord + 1 ) * size / dims)-1)
82 #define SIZE(coord,dims,size) (END(coord,dims,size)-BEGIN(coord,dims,size)+1)
107 void composeOutput(
aa_t * out,
int * outpos,
int * outsize,
aa_t * lout,
int loutsize,
int * gBegin,
int * gEnd);
243 #define h(i,j) (H[((i)*(lsize[1]+1))+(j)])
248 #define xback(i,j) (xTraceback[((i)*(lsize[1]+1))+(j)])
249 #define yback(i,j) (yTraceback[((i)*(lsize[1]+1))+(j)])
275 int main(
int argc,
char * argv[]){
280 MPI_Init(&argc,&argv);
281 MPI_Comm_rank(MPI_COMM_WORLD,&
rank);
282 MPI_Comm_size(MPI_COMM_WORLD,&
nProcs);
286 double_3int struct_d3i;
288 int blocks[4] = {1,1,1,1};
290 MPI_Datatype
types[4] = {MPI_DOUBLE, MPI_INT, MPI_INT, MPI_INT};
292 MPI_Address( &struct_d3i.val, &displ[0] );
293 MPI_Address( &struct_d3i.rank, &displ[1] );
294 MPI_Address( &struct_d3i.i, &displ[2] );
295 MPI_Address( &struct_d3i.j, &displ[3] );
296 MPI_Address( &struct_d3i, &displ[4] );
298 displ[0] -= displ[4];
299 displ[1] -= displ[4];
300 displ[2] -= displ[4];
301 displ[3] -= displ[4];
303 MPI_Type_struct(4, blocks, displ, types, &MPI_DOUBLE_3INT);
304 MPI_Type_commit( &MPI_DOUBLE_3INT );
320 int periods[2] = {0,0};
322 MPI_Cart_create(MPI_COMM_WORLD,2,
dims,periods,0,&
comm);
338 fprintf(stderr,
"There are inactive processors\n");
340 MPI_Abort(
comm,EXIT_FAILURE);
347 ALL_SEQUENTIAL_BEGIN(seq1);
350 printf(
" Dim1: Block begin %2d- (size %2d)\n",
lbegin[0],
lsize[0]);
351 printf(
" Dim2: Block begin %2d- (size %2d)\n",
lbegin[1],
lsize[1]);
353 ALL_SEQUENTIAL_END(seq1);
367 double time_comp_read = 0;
368 double time_comp_hmatrix = 0;
369 double time_comp_back = 0;
371 double time_comp_distr = 0;
372 double time_comp_syncH = 0;
373 double time_comp_syncB = 0;
374 double time_comp_compose = 0;
395 p1 = malloc(
sizeof(
aa_t)*((
size_t)(
size[0]+1)));
396 p2 = malloc(
sizeof(
aa_t)*((
size_t)(
size[1]+1)));
446 printfroot(
"=== Iteration: %d/%d ===\n\n",iter,iterations);
455 time_comp_read += (time_phaseE-time_phaseS);
464 time_comp_distr += (time_phaseE-time_phaseS);
474 time_comp_syncH += (time_phaseE-time_phaseS);
483 time_comp_hmatrix += (time_phaseE-time_phaseS);
493 time_comp_syncH += (time_phaseE-time_phaseS);
506 time_comp_syncB += (time_phaseE-time_phaseS);
515 time_comp_back += (time_phaseE-time_phaseS);
524 time_comp_syncB += (time_phaseE-time_phaseS);
533 time_comp_compose += (time_phaseE-time_phaseS);
570 timers[
T_LOCAL][0] = time_comp_read;
571 timers[
T_LOCAL][1] = time_comp_hmatrix;
572 timers[
T_LOCAL][2] = time_comp_back;
573 timers[
T_LOCAL][3] = time_comp_distr;
574 timers[
T_LOCAL][4] = time_comp_syncH;
575 timers[
T_LOCAL][5] = time_comp_syncB;
576 timers[
T_LOCAL][6] = time_comp_compose;
578 #define allTimers(timer) timers[T_MIN][timer],timers[T_AVG][timer],timers[T_MAX][timer]
580 MPI_Reduce(timers[0], timers[1], 7, MPI_DOUBLE, MPI_MIN, 0,
comm);
581 MPI_Reduce(timers[0], timers[2], 7, MPI_DOUBLE, MPI_SUM, 0,
comm);
582 MPI_Reduce(timers[0], timers[3], 7, MPI_DOUBLE, MPI_MAX, 0,
comm);
593 printf(
"=== Result ===\n");
594 printf(
"Init time: %f\n",time_initE-time_initS);
595 printf(
"Comp time: %f\n",time_compE-time_compS);
596 printf(
" Read protein: min: %f, avg: %f, max: %f \n",
allTimers(
T_READ));
600 printf(
" Backtracking: min: %f, avg: %f, max: %f \n",
allTimers(
T_BACK));
619 printf(
"\nInputset too big to print to stdout\n");
633 MPI_Comm_free(&
comm);
634 MPI_Type_free(&MPI_DOUBLE_3INT);
676 ALL_SEQUENTIAL_BEGIN(seq2)
678 printf("Coords %d
x %d\n",
lcoords[0],lcoords[1]);
679 printf("Local protein 1: ");
681 printf("Local protein 2: ");
684 ALL_SEQUENTIAL_END(seq2)
698 h_t array2[lsize[0]+1];
707 MPI_Cart_rank(
comm,pcoords,&prank);
710 MPI_Recv(array1, lsize[1], MPI_H, prank, 0,
comm, MPI_STATUS_IGNORE);
713 for(j=0; j<lsize[1]; j++){
714 h(0,j+1) = array1[j];
728 MPI_Cart_rank(
comm,pcoords,&prank);
731 MPI_Recv(array2, lsize[0]+1, MPI_H, prank, 0,
comm, MPI_STATUS_IGNORE);
734 for(i=0; i<lsize[0]+1; i++){
750 h_t array1[lsize[1]];
751 h_t array2[lsize[0]+1];
757 if(pcoords[0] <
dims[0]){
760 MPI_Cart_rank(
comm,pcoords,&prank);
763 for(j=0; j<lsize[1]; j++){
764 array1[j] =
h(lsize[0],j+1);
767 MPI_Send(array1, lsize[1], MPI_H, prank, 0,
comm);
775 if(pcoords[1] <
dims[1]){
778 MPI_Cart_rank(
comm,pcoords,&prank);
781 for(i=0; i<lsize[0]+1; i++){
782 array2[i] =
h(i,lsize[1]);
784 MPI_Send(array2, lsize[0]+1, MPI_H, prank, 0,
comm);
802 for (i=0;i<=lsize[0];i++){
810 for (j=0;j<=lsize[1];j++){
823 for(i=1; i<lsize[0]+1; i++){
824 for(j=1; j<lsize[1]+1; j++){
833 h_t max = MAX4(diag,down,right,0,&idx);
840 }
else if ( idx == 1 ) {
843 }
else if ( idx == 2 ) {
872 ALL_SEQUENTIAL_BEGIN(seq3);
879 for (j=0;j<=lsize[1];j++){
883 printf(
"%6c",AA2char(
lp2[j]));
886 for (i=0;i<=lsize[0];i++){
891 printf(
"%c |",AA2char(
lp1[i]));
893 for (j=0;j<=lsize[1];j++){
894 printf(
"%6.1f",(
double)
h(i,j));
900 ALL_SEQUENTIAL_END(seq3);
907 ALL_SEQUENTIAL_BEGIN(seq4)
910 printf("coords %d
x %d\n",
lcoords[0],lcoords[1]);
914 for (j=0;j<=lsize[1];j++){
918 printf(
"%8c",AA2char(
lp2[j]));
921 for (i=0;i<=lsize[0];i++){
926 printf(
"%c |",AA2char(
lp1[i]));
928 for (j=0;j<=lsize[1];j++){
935 ALL_SEQUENTIAL_END(seq4)
947 double_3int Max, outMax;
956 MPI_Allreduce(&Max, &outMax, 1, MPI_DOUBLE_3INT,
opHMaxLoc,
comm);
960 printfroot(
"Max %f in proc: %d\n\n",outMax.val, outMax.rank);
964 if(rank == outMax.rank){
1012 if( i == -1 || j == -1 ){
1016 }
else if(
h(i,j) > 0 && i == 0 ){
1020 }
else if (
h(i,j) > 0 && j == 0 ){
1043 int pos=lsize[0]+lsize[1]+1;
1047 while (i>0 && j>0 &&
h(i,j) > 0){
1049 int movex = (i>
xback(i,j));
1050 int movey = (j>
yback(i,j));
1055 if (movex && movey) {
1069 i=
xback(tempi,tempj);
1070 j=
yback(tempi,tempj);
1093 ALL_SEQUENTIAL_BEGIN(seq5);
1094 printf(
"Processor: %d/%d, ",rank,nProcs);
1095 printf(
"Coords %d x %d\n",lcoords[0],lcoords[1]);
1109 ALL_SEQUENTIAL_END(seq5);
1119 MPI_Request request;
1120 MPI_Irecv(&lprotein[1], lsize[dim], MPI_AA, 0, 0,
comm, &request);
1124 MPI_Wait(&request,MPI_STATUS_IGNORE);
1134 MPI_Cart_coords(
comm,p,2,pcoords);
1139 void * buff = &protein[pbegin + 1];
1141 MPI_Send(buff, psize, MPI_AA, p, 0,
comm);
1146 MPI_Wait(&request,MPI_STATUS_IGNORE);
1158 pcoords[0] = lcoords[0];
1159 pcoords[1] = lcoords[1];
1167 if(pcoords[0] < 0)
return;
1168 if(pcoords[1] < 0)
return;
1173 MPI_Cart_rank(
comm,pcoords,&prank);
1174 MPI_Send(&pos, 1, MPI_INT, prank, 0,
comm);
1183 pcoords[0] = lcoords[0];
1184 pcoords[1] = lcoords[1];
1191 if(pcoords[0] >=
dims[0])
return;
1192 if(pcoords[1] >=
dims[1])
return;
1196 MPI_Cart_rank(
comm,pcoords,&prank);
1197 MPI_Recv(pos, 1, MPI_INT, prank, 0,
comm, MPI_STATUS_IGNORE);
1223 #define MIN(a,b) (((a)<(b))?(a):(b))
1224 #define MAX(a,b) (((a)>(b))?(a):(b))
1232 MPI_Request request[4];
1235 MPI_Isend(&loutsize, 1, MPI_INT, 0, 1,
comm, &request[0]);
1240 MPI_Isend(gBegin, 1, MPI_INT, 0, 1,
comm, &request[1]);
1241 MPI_Isend(gEnd, 1, MPI_INT, 0, 1,
comm, &request[2]);
1242 MPI_Isend(lout, loutsize, MPI_AA, 0, 1,
comm, &request[3]);
1247 MPI_Wait(&request[0],MPI_STATUS_IGNORE);
1249 MPI_Wait(&request[1],MPI_STATUS_IGNORE);
1250 MPI_Wait(&request[2],MPI_STATUS_IGNORE);
1251 MPI_Wait(&request[3],MPI_STATUS_IGNORE);
1269 for(p=nProcs-1; p>=0; p--){
1273 MPI_Recv(&poutsize,1,MPI_INT,p,1,
comm,MPI_STATUS_IGNORE);
1276 if(!(poutsize > 0))
continue;
1281 MPI_Recv(&pgBegin,1,MPI_INT,p,1,
comm,MPI_STATUS_IGNORE);
1282 MPI_Recv(&pgEnd,1,MPI_INT,p,1,
comm,MPI_STATUS_IGNORE);
1290 minBegin =
MIN(minBegin,pgBegin);
1291 maxEnd =
MAX(maxEnd,pgEnd);
1295 (*outpos) -= poutsize;
1296 (*outsize) += poutsize;
1299 MPI_Recv(&out[(*outpos)],poutsize,MPI_AA,p,1,
comm,MPI_STATUS_IGNORE);
1309 MPI_Wait(&request[0],MPI_STATUS_IGNORE);
1311 MPI_Wait(&request[1],MPI_STATUS_IGNORE);
1312 MPI_Wait(&request[2],MPI_STATUS_IGNORE);
1313 MPI_Wait(&request[3],MPI_STATUS_IGNORE);
void phase_distribute_sequences()
void printProteinMatch(HitTile_aa_t p, int begin, int end)
void readProtein(ProteinFile *fprotein, HitTile_aa_t *protein, int psize)
void debug_show_matrices()
#define CHECK_NULL(check)
void openProtein(ProteinFile *fprotein, char *filename)
#define BEGIN(coord, dims, size)
void recv_Back(int dir, int *pos)
void input_parameters(int argc, char *argv[])
void phase_compose_sequence()
HitTile_trace_t yTraceback
void initPAM(char *filename)
void printProtein(HitTile_aa_t p, int offset, int psize)
void debug_show_backtracking()
void composeOutput(HitTile_aa_t out, int *outpos, int *outsize, HitTile_aa_t lout, int loutpos, int loutsize, int *gBegin, int *gEnd)
void distributeProtein(HitTile_aa_t protein, HitTile_aa_t lprotein, int dim)
void phase_send_hmatrix()
HitTile_trace_t xTraceback
int main(int argc, char *argv[])
void send_Back(int dir, int pos)
void phase_recv_hmatrix()
void phase_read_sequences()
#define SIZE(coord, dims, size)
void phase_comp_hmatrix()