简体   繁体   中英

compiling a mpi project with mingw64

i'm trying to get following code running with the "mpiexec -n 4 myprogram" command.

#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). 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. if i compile it to a x86 exe it runs as intended. so whats going wrong? is mpi incompatible with programs compiled by 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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