简体   繁体   English

C-MPI子进程收到不正确的字符串

[英]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: 我正在制作一个MPI密码破解程序,它使用蛮力破解SHA512哈希键,我的代码可以很好地使用1个密码和多个进程,或多个密码和1个进程,但是当我使用多个密码和多个进程时,我得到以下错误:

[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. 我认为这是由进程等级1接收到字符串“ /”而不是密码哈希值引起的。 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: 我还注意到我的代码有些奇怪,我在进程等级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: 假设我正在运行2个进程(不包括基本进程),并且进程2找到了密码,那么输出将是:

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? 当它只应发送一次,或者至少要发送两次时,这些值之一应该是2,不是两个都为1吗?

The main bulk of my code is as follows: Process 0 : 我的代码主要如下:进程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). (假设有一个,目前是一个无限循环,但在解决该问题之前,我想用2个密码进行排序)。

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. 永远不会完全清楚探针与接收有何不同,但是我想探针只是标记某些更改,但实际上要将其从“队列”中取出,然后需要通过接收来收集它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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