简体   繁体   中英

C - MPI child processes receiving incorrect string

I am making a MPI password cracker, that uses brute force approach to crack a SHA512 hash key, I have code that works fine with 1 password and multiple processes, or multiple passwords and 1 process, but when I do multiple passwords & multiple processes I get the following error:

[ubuntu:2341] *** An error occurred in MPI_Recv
[ubuntu:2341] *** reported by process [191954945,1]
[ubuntu:2341] *** on communicator MPI_COMM_WORLD
[ubuntu:2341] *** MPI_ERR_TRUNCATE: message truncated
[ubuntu:2341] *** MPI_ERRORS_ARE_FATAL (processes in this communicator will now abort,
[ubuntu:2341] ***    and potentially your MPI job)

I believe this is caused by process rank #1 receiving a string "/" instead of the password hash. The issue is I am not sure why.

I have also noticed something strange with my code, I have the following loop in process rank 0:

      while(!done){
        MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &done, &status);
        if(done==1) {   
          for(i=1;i<size;i++){
            if(i!=status.MPI_SOURCE){
              printf("sending done to process %d\n", i);
              MPI_Isend(&done, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &request[i]);
            }   
          }
        }          
      }

Which keeps looping waiting for one of the child processes to alert it that it has found the password. Lets say I am running 2 processes (excluding the base process) and process 2 finds the password, the output will then be:

sending done to process 1
sending done to process 1

When it should only be sending that once, or at the least if it is sending it twice surely the one of those values should be 2, not both of them being 1?

The main bulk of my code is as follows: Process 0 :

      while(!feof(f))  {
      fscanf(f, "%s\n", buffer);
      int done = 0;
      int i, sm;
      // lengths of the word (we know it should be 92 though)
      length = strlen(buffer);
      // Send the password to every process except process 0
      for (sm=1;sm<size;sm++) {
        MPI_Send(&length, 1, MPI_INT, sm, 0, MPI_COMM_WORLD);
        MPI_Send(buffer, length+1, MPI_CHAR, sm, 0, MPI_COMM_WORLD);
      }
      // While the passwords are busy cracking - Keep probing. 
      while(!done){
        MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &done, &status);
        if(done==1) {   
          for(i=1;i<size;i++){
            if(i!=status.MPI_SOURCE){
              printf("sending done to process %d\n", i);
              MPI_Isend(&done, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &request[i]);
            }   
          }
        }          
      }
    }

Which loops through the file, grabs a new password, sends the string to the child processes, at which point they receive it:

    MPI_Recv(&length, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    printf("string to be recieived has %d characters\n", length);
    MPI_Recv(buffer, length+1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
    printf("Process %d received %s\n", rank, buffer); 

The child processes crack the password, then repeat with the next one. (assuming there is one, currently it's an infinite loop but I want to sort it out with 2 passwords before I fix that).

All processes recieve the correct password for the first time, it's when they grab the second password that only 1 process has the correct one and the rest receive a "/" character.

Alright, typical case of me getting worked up and over looking something simple. I'll leave this question just in case anyone else happens to have the same issue though.

I was forgetting to also receive the solution after probing it. Was never fully clear how probe differed from receive but I guess probe just flags something changes, but to actually take it out of the "queue" you need to then collect it with receive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM