簡體   English   中英

使用MPI的客戶端/服務器應用程序

[英]client/server application using MPI

我有兩個問題; 第一個是:

我要使用msmpi,我的意思是“只能使用mpi”,我們不能使用套接字,我的應用程序是關於可伸縮的分布式數據結構的; 最初,我們有一個服務器包含一個大小可變的文件(大小可以通過插入增加,而刪除則可以減小),並且當文件大小超過一定限制時,文件將被拆分,一半保留在第一台服務器中然后將后半部分移到新服務器上,依此類推...,並且需要始終將要檢索的數據地址告知客戶端,因此他應該具有文件拆分操作的圖像。 最后,我希望我說得更清楚。

第二個是:

我試圖用msmpi或mpich2編譯簡單的客戶端/服務器應用程序(下面的代碼源是波紋管),它不起作用,並給我錯誤消息“ mpi_open_port()中的致命錯誤以及堆棧的其他錯誤”,所以我在ubunto 11.10上安裝了open mpi,並嘗試運行與服務器端相同的示例,它給了我一個端口名,但在客戶端它給了我錯誤消息:

[user-Compaq-610:03833] [[39604,1],0] ORTE_ERROR_LOG: Not found in file ../../../../../../ompi/mca/dpm/orte/dpm_orte.c at line 155
[user-Compaq-610:3833] *** An error occurred in MPI_Comm_connect
[user-Compaq-610:3833] *** on communicator MPI_COMM_WORLD
[user-Compaq-610:3833] *** MPI_ERR_INTERN: internal error
[user-Compaq-610:3833] *** MPI_ERRORS_ARE_FATAL (your MPI job will now abort)
--------------------------------------------------------------------------
mpirun has exited due to process rank 0 with PID 3833 on
node toufik-Compaq-610 exiting without calling "finalize". This may
have caused other processes in the application to be
terminated by signals sent by mpirun (as reported here).

所以我很困惑這個問題是什么,我花了一段時間試圖解決它,如果有人可以幫助我,我將非常高興,並在此先感謝您。

源代碼在這里:

/* the server side */
#include <stdio.h>
#include <mpi.h>

main(int argc, char **argv)
{
    int my_id;
    char port_name[MPI_MAX_PORT_NAME];
    MPI_Comm newcomm;
    int passed_num;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &my_id);

    passed_num = 111;

    if (my_id == 0)
    {
    MPI_Open_port(MPI_INFO_NULL, port_name);
    printf("%s\n\n", port_name); fflush(stdout);
    } /* endif */

    MPI_Comm_accept(port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &newcomm); 

    if (my_id == 0)
    {
    MPI_Send(&passed_num, 1, MPI_INT, 0, 0, newcomm);
    printf("after sending passed_num %d\n", passed_num); fflush(stdout);
    MPI_Close_port(port_name);
    } /* endif */

    MPI_Finalize();

    exit(0);

} /* end main() */

在客戶端:

#include <stdio.h>
#include <mpi.h>

int main(int argc, char **argv)
{
    int passed_num;
    int my_id;
    MPI_Comm newcomm;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &my_id);

    MPI_Comm_connect(argv[1], MPI_INFO_NULL, 0, MPI_COMM_WORLD, &newcomm); 

    if (my_id == 0)
    {
    MPI_Status status;
    MPI_Recv(&passed_num, 1, MPI_INT, 0, 0, newcomm, &status);
    printf("after receiving passed_num %d\n", passed_num); fflush(stdout);
    } /* endif */

    MPI_Finalize();

    return 0;   
    //exit(0);

} /* end main() */

您如何精確地運行該應用程序? 似乎提供的客戶端和服務器代碼是相同的。

通常,所有(MPI)流程的代碼都是相同的,並且if (my_id == 0) { ... } ,程序將根據代碼段決定按等級執行什么。 該應用程序使用mpiexec執行。 例如, mpiexec -n 2 ./application將在一個MPI_COMM_WORLD通信器中運行兩個MPI進程,它們的等級分別為12 過程的確切執行位置(在同一節點上還是在不同節點上)取決於配置。

不過,您應該使用MPI_Open_port創建端口,並將其傳遞給MPI_Comm_connect 這是有關如何使用這些功能的示例: MPI_Comm_connect

此外,對於MPI_Recv ,必須有相應的MPI_Send 否則,接收過程將永遠等待。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM