Skip to content
Snippets Groups Projects
Commit 0dd4762a authored by alexgara's avatar alexgara
Browse files

seem to fix

parent 64fb0751
No related branches found
No related tags found
No related merge requests found
......@@ -2,3 +2,4 @@ align_omp
align_seq
align_mpi
align_cuda
log.txt
......@@ -32,7 +32,7 @@
#define END_SIG -2
/* Macro for checking mpi funcs and print if there is a error */
#define MPI_CHEK_FUCKTION( call ) {int ierr = call; int resultlen; if (ierr != MPI_SUCCESS){ char error_msg[MPI_MAX_ERROR_STRING]; MPI_Error_string(ierr, error_msg, &resultlen); fprintf(stderr, "MPI fallo en linea (%d):\n%s\n\n", __LINE__, error_msg); MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); fflush(stdout);}}
#define MPI_CHECK_FUNCTION( call ) {int ierr = call; int resultlen; if (ierr != MPI_SUCCESS){ char error_msg[MPI_MAX_ERROR_STRING]; MPI_Error_string(ierr, error_msg, &resultlen); fprintf(stderr, "MPI fallo en linea (%d):\n%s\n\n", __LINE__, error_msg); MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); fflush(stdout);}}
/*
* Function: Increment the number of pattern matches on the sequence positions
......@@ -360,7 +360,6 @@ int main(int argc, char *argv[]) {
rng_t random_local = random;
rng_skip(&random_local, my_begin);
generate_rng_sequence( &random_local, prob_G, prob_C, prob_A, sequence, my_size);
//rng_skip(&random, seq_length);
#ifdef DEBUG
/* DEBUG: Print sequence and patterns */
......@@ -397,7 +396,6 @@ int main(int argc, char *argv[]) {
unsigned long pat;
//MPI_Request request;
MPI_Status status;
//int send_to_continue_flag = 0;
// [0]=my_begin+start | [1]= tamaño ya leido del patorn | [2]= numero de patrón
......@@ -413,6 +411,13 @@ int main(int argc, char *argv[]) {
MPI_Abort( MPI_COMM_WORLD, EXIT_FAILURE );
}
/* info for rank and my_size distrib
printf("rank[%d] my_size=%lu, my_begin=%lu\n", rank, my_size, my_begin);
fflush(stdout);
*/
MPI_CHECK_FUNCTION(MPI_Barrier(MPI_COMM_WORLD));
for( pat=0; pat < pat_number; pat++ ) {
/* 5.1. For each posible starting position */
......@@ -429,44 +434,27 @@ int main(int argc, char *argv[]) {
envio_array[2]=pat;
//Envio el parton para que continue el siguente que le toca
MPI_CHEK_FUCKTION(MPI_Send(envio_array, 3, MPI_UNSIGNED_LONG, rank+1, TAG_NO_COMPLETE, MPI_COMM_WORLD));
//printf("\n ENVIA(%d) rank=%d a rank+1=%d pat=%lu\n", (1), rank, rank+1, envio_array[2]);
MPI_CHECK_FUNCTION(MPI_Send(envio_array, 3, MPI_UNSIGNED_LONG, rank+1, TAG_NO_COMPLETE, MPI_COMM_WORLD));
//printf("\n ENVIA(%d) rank=%d a rank+1=%d pat=%lu, START=%lu, LENGHT=%lu\n", (1), rank, rank+1, envio_array[2], envio_array[0], envio_array[1]);
//fflush(stdout);
//send_to_continue_flag = 1;
break;
}
else if ( sequence[start + ind] != pattern[pat][ind] ) break;
}
/* 5.1.2. Check if the loop ended with a match */
//Check if is outside of the loop and the pattern continue in other
/*if(send_to_continue_flag){
send_to_continue_flag = 0;
break;
}*/
if ( ind == pat_length[pat] ) {
pat_found[pat] = my_begin + start;
//printf("RANK(%d) encuentra patrón=%lu\n",rank, pat);
break;
}
}
}
//This will be the las message that rank+1 will recive <= Beacause of MPI politics FIFO(non-overtaking)
//If first finish then send signal that it has no more to do
if(rank == 0){
envio_array[0] = (unsigned long) END_SIG;
envio_array[1] = (unsigned long) END_SIG;
envio_array[2] = (unsigned long) END_SIG;
MPI_CHEK_FUCKTION(MPI_Send(envio_array, 3, MPI_UNSIGNED_LONG, rank+1, TAG_NO_COMPLETE, MPI_COMM_WORLD));
//printf("\n ENVIA FIN rank=%d a rank+1=%d \n", rank, rank+1);
fflush(stdout);
}
/* Until this part all fine
MPI_CHEK_FUCKTION(MPI_Barrier(MPI_COMM_WORLD));
/**
MPI_CHECK_FUNCTION(MPI_Barrier(MPI_COMM_WORLD));
printf("==================\n rank=%d LLEGA pat=%lu, sig=%d\n", rank, pat, rank+1);
fflush(stdout);
MPI_CHEK_FUCKTION(MPI_Barrier(MPI_COMM_WORLD));
MPI_CHECK_FUNCTION(MPI_Barrier(MPI_COMM_WORLD));
*/
//NOW PROCESS CHECK FOR THE REAMAING PATTERN THAT ITS PREVIOUS DOSENT HAVE FOUND
......@@ -474,41 +462,27 @@ int main(int argc, char *argv[]) {
while(1 && (rank != 0)){
//First check if the previous process has finished & have nothing more to do
MPI_CHEK_FUCKTION(MPI_Recv(recibo_array, 3, MPI_UNSIGNED_LONG, rank-1, MPI_ANY_TAG, MPI_COMM_WORLD, &status));
MPI_CHECK_FUNCTION(MPI_Recv(recibo_array, 3, MPI_UNSIGNED_LONG, rank-1, TAG_NO_COMPLETE, MPI_COMM_WORLD, &status));
//else continue because the rank-1 send work to do
start_r = recibo_array[0]; //Were the patter was start to be detected
length_r = recibo_array[1]; //Lenght already checked
pat_r = recibo_array[2]; //Pattern searching
//THEN its end sigal the first so no more thing to do
if(pat_r == (unsigned long) END_SIG){
/*
printf("\n GET FIN rank=%d desde rank-1=%d \n", rank, status.MPI_SOURCE);
fflush(stdout);
*/
if(rank != nprocs-1){
envio_array[0] = END_SIG;
envio_array[1] = END_SIG;
envio_array[2] = END_SIG;
MPI_CHEK_FUCKTION(MPI_Send(envio_array, 3, MPI_UNSIGNED_LONG, rank+1, TAG_NO_COMPLETE, MPI_COMM_WORLD));
/*
printf("\n ENVIA FIN rank=%d a rank+1=%d \n", rank, rank+1);
fflush(stdout);
*/
}
break;
}
//else {
/*
printf("\n RECIBE rank=%d desde rank-1=%d pat=%lu con TAG=%d\n" ,rank, status.MPI_SOURCE, recibo_array[2], status.MPI_TAG);
else {
printf("\n RECIBE rank=%d desde rank-1=%d pat=%lu con TAG=%d, START=%lu, LENGHT=%lu\n" ,rank, status.MPI_SOURCE, pat_r, status.MPI_TAG, start_r, length_r);
fflush(stdout);
}
*/
//}
//search for the pattern in my space
......@@ -521,34 +495,38 @@ int main(int argc, char *argv[]) {
envio_array[2]=pat_r;
//Send to the next rank
MPI_CHEK_FUCKTION(MPI_Send(envio_array, 3, MPI_UNSIGNED_LONG, rank+1, TAG_NO_COMPLETE, MPI_COMM_WORLD));
MPI_CHECK_FUNCTION(MPI_Send(envio_array, 3, MPI_UNSIGNED_LONG, rank+1, TAG_NO_COMPLETE, MPI_COMM_WORLD));
/*
printf("\n ENVIA(%d) rank=%d a rank+1=%d pat=%lu\n", (1), rank, rank+1, envio_array[2]);
printf("\n ENVIA(%d) rank=%d a rank+1=%d pat=%lu, START=%lu, LENGHT=%lu\n", (2), rank, rank+1, envio_array[2], envio_array[0], envio_array[1]);
fflush(stdout);
*/
//send_to_continue_flag = 1;
break;
}
else if ( sequence[ind] != pattern[pat_r][ind+length_r] ) break;
}
//Check if is outside of the loop and the pattern continue in other
/*if(send_to_continue_flag){
send_to_continue_flag = 0;
break;
}*/
// else we have a match
if ( ind+length_r == pat_length[pat_r] ) {
pat_found[pat_r] = start_r;
//printf("RANK(%d) encuentra patrón=%lu\n",rank, pat_r);
break;
}
}
//Wait until all the process finish
//MPI_CHEK_FUCKTION(MPI_Barrier(MPI_COMM_WORLD));
if(rank != nprocs-1){
envio_array[0] =(unsigned long) END_SIG;
envio_array[1] =(unsigned long) END_SIG;
envio_array[2] = (unsigned long)END_SIG;
MPI_CHECK_FUNCTION(MPI_Send(envio_array, 3, MPI_UNSIGNED_LONG, rank+1, TAG_NO_COMPLETE, MPI_COMM_WORLD));
//printf("\n ENVIA FIN rank=%d a rank+1=%d \n", rank, rank+1);
//fflush(stdout);
}
//Wait until all the process finish
//MPI_CHECK_FUNCTION(MPI_Barrier(MPI_COMM_WORLD));
/*
MPI_CHEK_FUCKTION(MPI_Barrier(MPI_COMM_WORLD));
MPI_CHECK_FUNCTION(MPI_Barrier(MPI_COMM_WORLD));
printf("==================\n rank=%d LLEGA pat=%lu, sig=%d\n", rank, pat, rank+1);
fflush(stdout);
*/
......@@ -556,7 +534,7 @@ int main(int argc, char *argv[]) {
unsigned long *recive_pat_found;
//Define a recv buffer for for the master
if( rank == 0 || rank == 1 || rank == 2){
if(rank==0){
recive_pat_found = (unsigned long *)malloc( sizeof(unsigned long) * pat_number );
if ( recive_pat_found == NULL ) {
fprintf(stderr,"\n-- Error allocating aux pattern structure for size: %d\n", pat_number );
......@@ -564,29 +542,7 @@ int main(int argc, char *argv[]) {
}
}
//Wait to all process, so we get all the patterns
//MPI_CHEK_FUCKTION(MPI_Barrier(MPI_COMM_WORLD));
// rank 0 will be the master
/*if(rank == 0){
//Get the min pat_found)
MPI_CHEK_FUCKTION(MPI_Reduce(pat_found, recive_pat_found, pat_number, MPI_UNSIGNED_LONG, MPI_MIN, 0, MPI_COMM_WORLD));
//Send the pat_found to the other rank that will perform checksums
MPI_CHEK_FUCKTION(MPI_Isend(recive_pat_found, pat_number, MPI_UNSIGNED_LONG, 1,TAG_SEND_PAT_FOUND,MPI_COMM_WORLD, &request ));
MPI_CHEK_FUCKTION(MPI_Isend(recive_pat_found, pat_number, MPI_UNSIGNED_LONG, 2,TAG_SEND_PAT_FOUND,MPI_COMM_WORLD, &request ));
}
else {
//The other ranks send to the master
MPI_CHEK_FUCKTION(MPI_Reduce(pat_found, NULL, pat_number, MPI_UNSIGNED_LONG, MPI_MIN, 0, MPI_COMM_WORLD));
if(rank == 1 || rank == 2){
MPI_CHEK_FUCKTION(MPI_Recv(recive_pat_found, pat_number, MPI_UNSIGNED_LONG, 0, TAG_SEND_PAT_FOUND, MPI_COMM_WORLD, &status));
}
}*/
MPI_CHEK_FUCKTION(MPI_Reduce(pat_found, recive_pat_found, pat_number, MPI_UNSIGNED_LONG, MPI_MIN, 0, MPI_COMM_WORLD));
MPI_CHECK_FUNCTION(MPI_Reduce(pat_found, recive_pat_found, pat_number, MPI_UNSIGNED_LONG, MPI_MIN, 0, MPI_COMM_WORLD));
/*printf("recive_pat_found:");
for( debug_pat=0; debug_pat<pat_number; debug_pat++ ) {
......@@ -610,28 +566,6 @@ int main(int argc, char *argv[]) {
}
}
//rank 1 calculate checksum_found
/*if(rank == 1){
for(ind=0;ind<pat_number;ind++)
if(pat_found[ind] != (unsigned long) NOT_FOUND)
checksum_found = (checksum_found + pat_found[ind]) % CHECKSUM_MAX;
// Send to rank == 0 the checksum
MPI_CHEK_FUCKTION(MPI_Isend(&checksum_found, 1, MPI_UNSIGNED_LONG, 0, TAG_SEND_CHECKSUM, MPI_COMM_WORLD, &request));
}*/
//Recv the calculated checksum from rank 1
/*if( rank == 0) {
MPI_CHEK_FUCKTION(MPI_Recv(&checksum_found, 1, MPI_UNSIGNED_LONG, 1, TAG_SEND_CHECKSUM, MPI_COMM_WORLD, &status));
}*/
// rank 2 TODO calculate checksum_matches
/** Esta parte de momento la consideramos opcional
for( ind=0; ind < seq_length; ind++) {
if ( seq_matches[ind] != (unsigned long)NOT_FOUND )
checksum_matches = ( checksum_matches + seq_matches[ind] ) % CHECKSUM_MAX;
}
**/
#ifdef DEBUG
/* DEBUG: Write results */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment