Author Topic: C programming with MPI.H  (Read 24804 times)

Offline Clipper_101

  • Single posting newcomer
  • *
  • Posts: 2
C programming with MPI.H
« on: February 26, 2013, 01:29:07 pm »
Hello to all!

I have collided with some problems, I installed MPICH2 and followed this instructions: http://ru.scribd.com/doc/50326868/MPICH2-Code-Blocks-IDE   I also added the C:\Program Files\MPICH2\bin to PATH system variable
But Codeblocks can't build my programm, errors are undefined reference to MPI_Init, MPI_Finalize

Here is the sample code:
   #include <stdio.h>
   #include <mpi.h>

   main(int argc, char **argv)
   {
      int ierr;

      ierr = MPI_Init(&argc, &argv);
      printf("Hello world\n");

      ierr = MPI_Finalize();
   }

Can someone say why Codeblocks refuses to work with MPI? My system works on Windows 7 HP 64bit's, Codeblocks and MPICH2 are also 64 bits. Really hope on your help. Thanks in advance!

Online stahta01

  • Lives here!
  • ****
  • Posts: 6789
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Clipper_101

  • Single posting newcomer
  • *
  • Posts: 2
Re: C programming with MPI.H
« Reply #2 on: February 26, 2013, 02:04:04 pm »
This what I get:
mingw32-gcc.exe   -I"C:\Program Files\MPICH2\include"  -c C:\Users\Almas\Desktop\OS_LAB1\MPI_TEST\main.c -o C:\Users\Almas\Desktop\OS_LAB1\MPI_TEST\main.o
mingw32-g++.exe  -o C:\Users\Almas\Desktop\OS_LAB1\MPI_TEST\main.exe C:\Users\Almas\Desktop\OS_LAB1\MPI_TEST\main.o   "C:\Program Files\MPICH2\lib\mpi.lib"
C:\Users\Almas\Desktop\OS_LAB1\MPI_TEST\main.o:main.c:(.text+0x38): undefined reference to `MPI_Init'
C:\Users\Almas\Desktop\OS_LAB1\MPI_TEST\main.o:main.c:(.text+0x4c): undefined reference to `MPI_Finalize'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 0 warnings (0 minutes, 0 seconds)
 

Online stahta01

  • Lives here!
  • ****
  • Posts: 6789
    • My Best Post
Re: C programming with MPI.H
« Reply #3 on: February 26, 2013, 03:19:42 pm »
This what I get:
mingw32-gcc.exe   -I"C:\Program Files\MPICH2\include"  -c C:\Users\Almas\Desktop\OS_LAB1\MPI_TEST\main.c -o C:\Users\Almas\Desktop\OS_LAB1\MPI_TEST\main.o
mingw32-g++.exe  -o C:\Users\Almas\Desktop\OS_LAB1\MPI_TEST\main.exe C:\Users\Almas\Desktop\OS_LAB1\MPI_TEST\main.o   "C:\Program Files\MPICH2\lib\mpi.lib"
C:\Users\Almas\Desktop\OS_LAB1\MPI_TEST\main.o:main.c:(.text+0x38): undefined reference to `MPI_Init'
C:\Users\Almas\Desktop\OS_LAB1\MPI_TEST\main.o:main.c:(.text+0x4c): undefined reference to `MPI_Finalize'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 0 warnings (0 minutes, 0 seconds)

Other than using your desktop to build the project; I see nothing wrong.
Did you download the right version of MPI.

The "http://www.mpich.org/static/tarballs/1.4.1p1/mpich2-1.4.1p1-win-ia32.msi" compiled for me on Windows 7 32 bit

I have no idea how to run the code; so never have ran it to see if it runs.

My build in case you can see the difference. Note: I compiled the example code from the website. I removed the warning from the build since the was not useful.

Code: [Select]
-------------- Build: Debug in testmpi (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -std=gnu++11 -Wall -fexceptions  -g  -Wmissing-include-dirs   -I"C:\Program Files\MPICH2\include"  -c V:\SourceCode\Projects\testmpi\main.cpp -o obj\Debug\main.o
mingw32-g++.exe  -o bin\Debug\testmpi.exe obj\Debug\main.o    "C:\Program Files\MPICH2\lib\mpi.lib"
Output size is 944.50 KB

Still compiles after removing the unusual options I had set
Code: [Select]
mingw32-g++.exe  -O2  -Wmissing-include-dirs   -I"C:\Program Files\MPICH2\include"  -c V:\SourceCode\Projects\testmpi\main.cpp -o obj\Release\main.o
mingw32-g++.exe  -o bin\Release\testmpi.exe obj\Release\main.o   -s  "C:\Program Files\MPICH2\lib\mpi.lib"
Output size is 467.00 KB
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 0 warnings (0 minutes, 1 seconds)


Tim S.
« Last Edit: February 26, 2013, 03:28:46 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Online stahta01

  • Lives here!
  • ****
  • Posts: 6789
    • My Best Post
Re: C programming with MPI.H
« Reply #4 on: February 26, 2013, 03:30:02 pm »
For any more progress the MPICH2 version and Compiler version will be needed.

FYI: I am using this like the web page example; it does not make a difference with my setup; but, it might with yours. 
Code: [Select]
#include "mpi.h"

Tim S.
« Last Edit: February 26, 2013, 03:32:25 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: C programming with MPI.H
« Reply #5 on: February 26, 2013, 03:34:46 pm »
Just a wild guess: it might be a name mangling problem.

Online stahta01

  • Lives here!
  • ****
  • Posts: 6789
    • My Best Post
Re: C programming with MPI.H
« Reply #6 on: February 26, 2013, 03:45:32 pm »
Just a wild guess: it might be a name mangling problem.

Very good theory; but, I just changed it to C code. Note: This is NOT enough to rule out "name mangling" as the cause.
But, it reduces it as a possibility.

Edit3: I am using gcc version 4.7.1 (tdm-1) with SJLJ exceptions; I believe this is the version shipped with CB-mingw version 12.11.

Code: [Select]
#include <stdio.h>
#include "mpi.h"
#include <string.h>

int main(int argc, char *argv[])
{
    int my_rank;
    int size;
    MPI_Init(&argc, &argv); /*START MPI */
    /*DETERMINE RANK OF THIS PROCESSOR*/
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
    /*DETERMINE TOTAL NUMBER OF PROCESSORS*/
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    printf("Hello world! I'm rank (processor number) %d of %d processor \n", my_rank, size);
    MPI_Finalize(); /* EXIT MPI */
    return 0;
}

And it still built OK.
Code: [Select]
mingw32-gcc.exe  -O2  -Wmissing-include-dirs   -I"C:\Program Files\MPICH2\include"  -c V:\SourceCode\Projects\testmpi\main.c -o obj\Release\main.o
mingw32-g++.exe  -o bin\Release\testmpi.exe obj\Release\main.o   -s  "C:\Program Files\MPICH2\lib\mpi.lib"
Output size is 9.00 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)

Tim S.
« Last Edit: February 26, 2013, 03:57:16 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline jarod42

  • Multiple posting newcomer
  • *
  • Posts: 82
Re: C programming with MPI.H
« Reply #7 on: February 26, 2013, 04:34:04 pm »
maybe a 32/64 bit issue ?