The MulticoreBSP Forums

A place to discuss the MulticoreBSP library and its applications, and for discussing the use of the Bulk Synchronous Parallel model on shared-memory architectures, or hybrid distributed/shared architectures.

You are not logged in.

#1 2013-05-30 18:16:31

Albert-Jan Yzelman
Moderator
Registered: 2011-08-04
Posts: 32

MulticoreBSP on Windows using Code::Blocks

Update 13/9/2019: this guide still applies, but be wary of version mismatches. See the post dated 13/9/2019 for one combination that works!

MulticoreBSP for C targets Linux specifically, but is designed to be portable to other systems: it depends only on the ANSI C99 standard, the POSIX threads (PThreads) extension, and the POSIX realtime extension.

Windows does not implement the latter two POSIX extensions. MulticoreBSP can still work on Windows, however, due to the following:

  • the pthreads-win32 project implements the PThreads interface for Windows;

  • we can substitute Windows-specific high-resolution timers instead of using POSIX realtime.

We ensure that MulticoreBSP for C can indeed compile correctly on Windows system using the above solutions, but in principle do not provide further support for Windows-users.

Still, on request, we have looked into what it takes to get MulticoreBSP for C running under the Code::Blocks IDE in Windows. Consider the following example program:

#include <mcbsp.h>
#include <stdio.h>

void spmd() {
    bsp_begin( bsp_nprocs()-1 > 0 ? bsp_nprocs()-1 : 1 );
    printf( "Hello world from thread %d in SPMD section two!\n", bsp_pid() );
    bsp_end();
}

int main( int argc, char **argv ) {
    bsp_begin( bsp_nprocs() );
    printf( "Hello world from thread %d in SPMD section one!\n", bsp_pid() );
    bsp_end();

    printf( "Initialising thread is in-between parallel SPMD sections one and two...\n" );

    bsp_init( &spmd, argc, argv );
    spmd();

    printf( "Initialising thread is about to exit...\n" );
    return 0;
}

This code runs two BSP SPMD sections: the first is a hello-world using all available cores; the second SPMD section does the same, but using one less core (with a minimum of 1).

To get this C-code running using MulticoreBSP and Code::Blocks, first start a new C `Console application' project, and copy-paste the above code in the main.c file. The code requires the MulticoreBSP for C library, so we should provide this. We have set up a pre-compiled static version here. We should also provide the mcbsp.h header, which is found here. We compiled this static library using the 2.8.0 version of pthreads-win32, so this library must be included too. We recommend using the pthreadGC2 version, and we require both the library and the dll.
To add the static libraries to the Code::Blocks project, go to `Project' in the menu-bar, and then to `Build options...'. Click on the `linker settings' tab, and add the libmcbsp and pthread libraries (the .a files). Then head over to the `Search directories' tab, and then to the `Compiler' sub-tab. There, add the path in which mcbsp.h resides.

Now the compilation paths are all set, and Code::Blocks is able to compile and run the above Hello World application. Our output looked as follows:

Hello world from thread 1 in SPMD section one!
Hello world from thread 3 in SPMD section one!
Hello world from thread 0 in SPMD section one!
Hello world from thread 2 in SPMD section one!
Initialising thread is in-between parallel SPMD sections one and two...
Hello world from thread 1 in SPMD section two!
Hello world from thread 2 in SPMD section two!
Hello world from thread 0 in SPMD section two!
Initialising thread is about to exit...

Process returned 0 (0x0)   execution time : 0.091 s
Press any key to continue.

Note that to run MulticoreBSP applications outside of Code::Blocks, the pthread-win32 DLL file should be in the executable path. Note also the DLL file should be of the same version as the application and library were compiled against.

This guide was written for the 1.1.0-release of MulticoreBSP for C. To pick up the latest version, look here. We will try to provide up-to-date cross-compiled static libraries for both 32-bits and 64-bits Windows versions.

Further questions, comments, tips, and so on, are welcome. We stress, however, that we have no in-depth experience with Code::Blocks, nor with development/deployment on Windows systems; you may have to rely on other helpful users should very specific issues arise. We also do not especially recommend the Code::Blocks IDE over any other available IDE, and hope the process described above is in fact similar to those required for other development environments.

Offline

#2 2013-06-03 13:07:27

Albert-Jan Yzelman
Moderator
Registered: 2011-08-04
Posts: 32

Re: MulticoreBSP on Windows using Code::Blocks

Apparently, one needs to be wary of using spaces within all paths associated with your project.

Should Code::Blocks fail to compile, please inspect the build log and check the compiler error message for malformed directory names, e.g., partial paths due to spaces. When encountered, try moving the project and all dependencies into a path that does not contain spaces (or other possibly ambiguous characters).

Offline

#3 2019-09-13 20:22:12

Albert-Jan Yzelman
Moderator
Registered: 2011-08-04
Posts: 32

Re: MulticoreBSP on Windows using Code::Blocks

A few years later, there are many more MinGW compiler versions out there that can cause incompatibilities. If the above guide nets you missing symbol errors of the forms mcbsp_perf_*, __impl_*PThread*, or __MinGW_*, you're likely in such a situation. The cleanest solution is to build a MulticoreBSP library from source under your current Windows installation, but this is not supported and thus requires some manual tinkering.

I've hence made sure at least one combination using a ready-to-go Code::Blocks version works as intended:
* MinGW + CodeBlocks version 17.12 [1,2]
* PThreads-win32 v2.1.9 [3]
* MulticoreBSP for C v2.0.4 pre-built 32-bit static library and header file [4,5]

You should use the x86 GC2 versions of the PThreads pre-built binaries, and you need both the DLL and the .a. To use MulticoreBSP for C in your Windows Code::Blocks project, simply add the bsp.h header [5] to your project and start coding. Before building, make sure to add the libmcbsp2.0.4.a [4] and libpthreadGC2.a (the x86 version!) [3] to your linker configuration as shown in [6]:

mcbsp-win32-1.png
The order of the static libraries matter-- the MulticoreBSP for C library should be linked first, because it has dependencies on the PThreads library.

Before running, make sure to put the pthreadGC2.dll (the x86 version!) [3] *in the same folder as your executable* (e.g., /path/to/project/bin/Release/ or /path/to/project/bin/Debug). Alternatively, the DLL could be added to your system's path. The final result should be as in [7]:

mcbsp-win32-2.png

The pre-built Win32 library [4] should work with all current and future MinGW v5.x.x and PThreads-win32 v2.9.x versions. The win64 pre-built binary (at http://www.multicorebsp.com/downloads/c/2.0.4/win64) is only compatible with the older MinGW v4.x.x.

[1] http://www.codeblocks.org/downloads/binaries#windows
[2] http://sourceforge.net/projects/codeblo … -setup.exe
[3] ftp://sourceware.org/pub/pthreads-win32 … 1-release/
[4] http://www.multicorebsp.com/downloads/c … bsp2.0.4.a
[5] http://www.multicorebsp.com/downloads/c/2.0.4/bsp.h
[6] http://www.multicorebsp.com/images/mcbsp-win32-1.png
[7] http://www.multicorebsp.com/images/mcbsp-win32-2.png

Offline

Board footer

Powered by FluxBB