由于我無法修復的 MPI Scatter Error,以下代碼在運行時失敗。在遵循檔案和其他類似的錯誤頁面時,我沒有看到任何問題。請幫忙。我正在使用 openmpi/4.0.5-gcc。
#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"
#define UPPER_LIMIT 4
#define master 0
int main(int argc, char *argv[])
{
int *data;
int process_id, total_process, temp_result;
int i, tag, final_result;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &process_id);
MPI_Comm_size(MPI_COMM_WORLD, &total_process);
MPI_Status status;
if ( total_process > UPPER_LIMIT )
{
if ( process_id == 0 )
printf("max allowed processes limit [%d] exceeded.\n", UPPER_LIMIT);
exit(0);
}
final_result = 0;
for ( i = 0; i < total_process; i ){
data[i] = (int)i;
}
int j;
for(j = 0; j < total_process; j ) {
printf("%d ", data[j]);
if(j==total_process-1)
printf("*** %d\n", process_id);
}
MPI_Scatter(data, total_process, MPI_INT, &temp_result, 1, MPI_INT, 0, MPI_COMM_WORLD);
if(process_id!=master){
temp_result = temp_result/process_id;
MPI_Reduce(&temp_result, &final_result, 1, MPI_INT, MPI_SUM, 1, MPI_COMM_WORLD);
}
if(final_result>0){
tag = process_id;
MPI_Send(&final_result, 1, MPI_INT, 0, tag, MPI_COMM_WORLD);
}
if(process_id==master){
MPI_Recv(&final_result, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
}
MPI_Finalize();
return 0;
}
錯誤日志
0 1 2 3 *** 0
0 1 2 3 *** 1
0 1 2 3 *** 2
0 1 2 3 *** 3
*** An error occurred in MPI_Scatter
*** reported by process [1855324161,0]
*** on communicator MPI_COMM_WORLD
*** MPI_ERR_TRUNCATE: message truncated
*** MPI_ERRORS_ARE_FATAL (processes in this communicator will now abort,
*** and potentially your MPI job)
MPI_Scatter 檔案
MPI_Scatter 將資料從一個行程發送到通信器中的所有其他行程
概要 int MPI_Scatter(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
輸入引數
sendbuf - 發送緩沖區的地址(選擇,僅在 root 中有意義)
sendcount - 發送到每個行程的元素數(整數,僅在根處有效)
sendtype - 發送緩沖區元素的資料型別(僅在根處有意義)(句柄)
recvcount - 接收緩沖區中的元素數(整數)
recvtype - 接收緩沖區元素的資料型別(句柄)
root - 發送行程的等級(整數)
comm - 通訊器(句柄)
輸出引數
recvbuf - 接收緩沖區的地址(選擇)
更新
將 MPI_Scatter 發送計數更新為 1 后,上述錯誤消失了,但程式保持理想狀態,并且沒有列印任何放置在 MPI_Scatter 行之后的內容。
MPI_Scatter(data, 1, MPI_INT, &temp_result, 1, MPI_INT, 0, MPI_COMM_WORLD);
uj5u.com熱心網友回復:
您參考相關行:“sendcount - 發送到每個行程的元素數(整數”。因此,如果您向每個行程發送 1 個元素,則需要將 sendcount 設定為 1,而不是total_process。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/364033.html
上一篇:C中BST程式的功能之一的問題
