我想創造出我的程序在這裏中止這裏是我的程序的一部分 我需要一個優雅地退出我的代碼 在這部分我想做一個閱讀輸入錯誤,在Rdinput()我如果發生錯誤,返回1 。隨着MPI優雅地退出
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#define MASTER 0
#define Abort(x) MPI_Abort(MPI_COMM_WORLD, x)
#define Bcast(send_data, count, type) MPI_Bcast(send_data, count, type, MASTER, GROUP) //root --> MASTER
#define Finalize() MPI_Finalize()
#define Init(x,y) MPI_Init(x,y)
#define Rank(x) MPI_Comm_rank(MPI_COMM_WORLD, x)
#define Size(x) MPI_Comm_size(MPI_COMM_WORLD, x)
int main(int argc, char **argv) /* Main routine of MGA program*/
{
if(rank == MASTER){
time (&start);
printf("Initialized at %s\n", ctime (&start));
printf("\t***********************************************************\n");
printf("\t** Program MGA **\n");
printf("\t** (Molecular Genetic Algorithm) **\n");
printf("\t** **\n");
printf("\t** **\n");
printf("\t** Principal Author: **\n");
printf("\t** Freddy F. Guimaraes **\n");
printf("\t** email: [email protected] **\n");
printf("\t** **\n");
printf("\t** Authors: **\n");
printf("\t** Rafael Carvalho Couto, Fabrício Sanches Paranhos, **\n");
// printf("\t** Robson de Souza Vieira. **\n");
printf("\t** **\n");
printf("\t***********************************************************\n\v");
printf("Reading input file: |");
printf("#");fflush(stdout);
error = RdInput(Infile, CHARMAX);
}
Bcast(&error, 1, INT);
Wait();
if(error = 1) MPI_Abort(1);
REST OF THE CODE
Finalize();
}
這裏走出來的......
[email protected]:~/MGA/MGA-2011-mpi$ mpirun -np 2 mga-2011.x
--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD
with errorcode 1.
NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.
--------------------------------------------------------------------------
Initialized at Wed May 30 11:34:46 2012
***********************************************************
** Program MGA **
** (Molecular Genetic Algorithm) **
** **
** **
** Principal Author: **
** Freddy F. Guimaraes **
** email: [email protected] **
** **
** Authors: **
** Rafael Carvalho Couto, Fabrício Sanches Paranhos, **
** **
***********************************************************
Reading input file: |#|
Error [RdInput]: The file "input.mga" is not available!
--------------------------------------------------------------------------
mpirun has exited due to process rank 0 with PID 7369 on
node einstein exiting improperly. There are two reasons this could occur:
1. this process did not call "init" before exiting, but others in
the job did. This can cause a job to hang indefinitely while it waits
for all processes to call "init". By rule, if one process calls "init",
then ALL processes must call "init" prior to termination.
2. this process called "init", but exited without calling "finalize".
By rule, all processes that call "init" MUST call "finalize" prior to
exiting or it will be considered an "abnormal termination"
This may have caused other processes in the application to be
terminated by signals sent by mpirun (as reported here).
--------------------------------------------------------------------------
[einstein:07368] 1 more process has sent help message help-mpi-api.txt/mpi-abort
[einstein:07368] Set MCA parameter "orte_base_help_aggregate" to 0 to see all help/error messages
我如何做才能正常退出蒙山錯誤代碼爲例
計劃完成蒙山錯誤代碼10
你在哪裏隱藏mpi_init? –
您共享的所有代碼與問題無關。所有與該問題相關的代碼都丟失了。我們不知道你是如何初始化或最終化MPI的,我們甚至不知道'rank'的定義在哪裏,或者你如何填充它。現在,它看起來像MPI從未被初始化。 – ArjunShankar
完全偏離主題的建議:考慮放棄大橫幅。當你打印幫助信息時,你可以有一個像「--help」這樣的開關,幷包含作者列表,或者你可以在你的程序的'man'頁面中包含作者列表。有人可能希望在腳本中使用你的程序的輸出,然後橫幅將是一個痛苦的脖子。 - 舉例來說,想象一下,如果'cat'程序在打印橫幅時就會發生什麼情況,只要您問它「貓」文件即可。 – ArjunShankar