locked
mpiexec RRS feed

  • Question

  • Hi

    I want to run my first program using  mpi  in .net.

    i run mpiexec -n 4 address and the program run for first process but the final result is true.

    the code is:
    int main (int argc, char *argv[])
    {
      int nprocs;           
      int rank;           
      int i, mysum, sum, imin, imax;
      const int N = 60;
     MPI_Init (&argc, &argv);    /* note: use argc and argv yourself only
                     * after this call */

      MPI_Comm_rank (MPI_COMM_WORLD, &rank);   
                  
      MPI_Comm_size (MPI_COMM_WORLD, &nprocs);  
      printf ("Hello, this is process %d of a total of %d\n", rank, nprocs);
     imin = (N / nprocs) * rank + 1;
      imax = imin + N / nprocs -1;

      mysum = 0;           
      for (i = imin; i <= imax; i++)
        mysum += i;



      MPI_Reduce (&mysum,&sum, 1,MPI_INT,MPI_SUM,0, MPI_COMM_WORLD);
     if (rank == 0)
        printf ("process zero reports: sum is %d\n", sum);
    MPI_Bcast (&sum,1, MPI_INT, 0, MPI_COMM_WORLD);
     printf ("process %d reports: mysum is %d and sum is %d\n", rank, mysum,
          sum);
      MPI_Allreduce (&mysum, &sum, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
      printf ("process %d reports again: mysum is %d and sum is %d\n",
          rank, mysum, sum);

      MPI_Finalize ();       
      getchar();
    }

    the result whit mpiexec is:

    Hello, this is process 0 of a total of a total of 4.

    process zero reports sum is 1830

    process 0 reports: mysum is 120 and sum is 1830

    process 0 reports again: mysum is 120 and sum is 1830.

    ..............................

    why the code doesn,t run for other 3 process?

    Thanks.

     

     

    Friday, July 15, 2011 4:53 PM

All replies

  • Is it possible your other processes run on other nodes (a cluster)? The output is local. The processes must be running otherwise the communication part would fail.
    Friday, July 15, 2011 8:19 PM

  • I am new in mpi and .net .i am glad that help me with more details .

    NO it is not possible for me.

    Is not any way that I can run and see all of them with one node?

     I run other program with mpi and i get the following error:

    error LNK2019: unresolved external symbol __RTC_CheckEsp referenced in function _main

    What does the mean of this error and how can I fix it?

    it,s one of program,s error.

    It has 33 error and all of them is LNK error.

    Your help is very appreciated!
    Saturday, July 16, 2011 6:42 PM
  • Hi Sara,

    Your MPI program looks right. The problem is at getchar() at the end of the program.

    1) your current program lets all process to call getchar(), which won't work except for the rank0 process.

    2) please only call getchar() from rank=0 process.

    Liwei

    Tuesday, July 19, 2011 10:45 PM
  • Thanks for your answer Liwei.

    But it doesn’t work yet and the result looks like previous one.

    And I think: Between MPI_INIT and MPI_FINALIZE is executed for each process, however getchar() is after MPI_FINALIZE .so it runs once for main function.

    Also It happened for hello world program . This is Hello world program:

    #include <mpi.h>

    #include <stdio.h>

    void main(int argc , char* argv[])

    { int npes, myrank;

    MPI_Init(&argc, &argv);

    MPI_Comm_size(MPI_COMM_WORLD, &npes);

    MPI_Comm_rank(MPI_COMM_WORLD,&myrank);

    printf("From process %d out of %d, Hello World!\n",myrank, npes);

    if(myrank==0)

    getchar();

    MPI_Finalize();

    }

    The output window appear and quickly disappear.it print out only for process 0 again.

    Wednesday, July 20, 2011 7:09 AM
  • Hello,

    What command do you use for your application?

    Also a suggestion is to add a line before the getchar(), eg: printf("Rank 0: Please enter:\n");fflush(stdout);

    So  you know whether the program executed.

    Thanks,

    James

    Tuesday, October 18, 2011 12:30 AM