MPi多重广播BIGNUM

时间:2019-01-26 17:58:34

标签: c openssl mpi broadcast

我有以下代码:

int MPIbcastBigNum(BIGNUM *num, int rank, char* purpoce){
    int size = BN_num_bytes(num);
    unsigned char *message = OPENSSL_malloc(size);

    if(!BN_bn2bin(num, message)) {
     fprintf(stderr, "RANK %d: Fail to allocate an array for key bytes \"%s\" \n", rank, purpoce);
     fflush(stderr);
     OPENSSL_free(message);
     return -1;    
    }

    //Do the actual Broadcast && Debug
    printf("RANK %d: Broaccasting bignum for purpoce \"%s\" \n", rank, purpoce);
    fflush(stdout);
    int value = MPI_Bcast(message, size, MPI_BYTE, rank, MPI_COMM_WORLD);
    switch(value) {
        case MPI_ERR_COMM:
         fprintf(stderr, "RANK %d: COMMUNICATIPN ERROR on BIGNUM sending for purpoce \"%s\" \n", rank, purpoce);
         fflush(stderr);
         OPENSSL_free(message);
         return -1;

        case MPI_ERR_COUNT:
         fprintf(stderr, "RANK %d: Invalid Size Count on BIGNUM sending for purpoce \"%s\" \n", rank, purpoce);
         fflush(stderr);
         OPENSSL_free(message);
         return -1;

        case MPI_ERR_TYPE:
         fprintf(stderr, "RANK %d: Invalid Data Type on BIGNUM sending for purpoce \"%s\" \n", rank, purpoce);
         fflush(stderr);
         OPENSSL_free(message);
         return -1;

        case MPI_ERR_BUFFER:
         fprintf(stderr, "RANK %d: Invalid Buffer on BIGNUM sending for purpoce \"%s\" \n", rank, purpoce);
         fflush(stderr);
         OPENSSL_free(message);
         return -1;

        default:
          printf("RANK %d: ALL OK on BIGNUM sending on purpoce \"%s\" \n", rank, purpoce);
          fflush(stdout);
    }

    //Cleanups
    OPENSSL_free(message);
    return 0;
}

我想做的是通过MPI发送OpenSSL BIGNUM。但是我的问题是每个BIGNUM的大小可能不相同。因此,我很想知道将数据的长度通知接收进程。

到目前为止,我认为首先广播大小为MPI_INT,然后将实际数据广播为n大小的MPI_BYTE数组。但是,当我尝试同时接收大小和BigNum时,这些怎么会不会混乱?

1 个答案:

答案 0 :(得分:1)

首先广播大小,然后广播数据是正确的事情。在这种情况下,订购不是问题。集体交流不能互相超越。点对点消息甚至可以保证消息对于一对发送者和接收者来说都是超车