简体   繁体   English

用mingw64编译一个mpi项目

[英]compiling a mpi project with mingw64

i'm trying to get following code running with the "mpiexec -n 4 myprogram" command. 我正在尝试使用“ mpiexec -n 4 myprogram”命令运行以下代码。

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

int main(int argc, char *argv[]) {
  int numprocs, rank, namelen;
  char processor_name[MPI_MAX_PROCESSOR_NAME];
  int iam = 0, np = 1;

  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Get_processor_name(processor_name, &namelen);

  #pragma omp parallel default(shared) private(iam, np)
  {
    np = omp_get_num_threads();
    iam = omp_get_thread_num();
    printf("Hello from thread %d out of %d from process %d out of %d on %s\n",
           iam, np, rank, numprocs, processor_name);
  }

  MPI_Finalize();
}

i'm using win7 x64, mpich2 x64, eclipse x64 and mingw64 (rubenvb build). 我正在使用win7 x64,mpich2 x64,eclipse x64和mingw64(rubenvb构建)。 it compiles well and also runs in eclipse environment (but there only with one process), but on the command line it immediatly closes without a result or an error. 它可以很好地编译,并且可以在eclipse环境中运行(但仅在一个进程中运行),但是在命令行中,它立即关闭而没有结果或错误。 if i compile it to a x86 exe it runs as intended. 如果我将其编译为x86 exe,它将按预期运行。 so whats going wrong? 那么怎么了? is mpi incompatible with programs compiled by mingw64? MPI与mingw64编译的程序不兼容吗?

If you build it as a console program, the program will run, finish and then immediately close as there's likely no command sent by the program to hold the console open. 如果将其构建为控制台程序,则该程序将运行,完成然后立即关闭,因为该程序可能未发送任何命令来保持控制台打开。

If you run it again, this time by going into the console first and running it from the command line, the console will stay open as it's running as a seperate process, instead of being tied to your program (as is the case when double clicking to run the program). 如果您再次运行它,这一次(首先进入控制台并从命令行运行它),控制台将保持打开状态,因为它作为一个单独的进程运行,而不是与您的程序捆绑在一起(就像双击时一样)运行程序)。

As for not running in parallel, make sure you have the flag -fopenmp in both the compilation and linking stages. 至于不并行运行,请确保在编译和链接阶段都具有-fopenmp标志。

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

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