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
Registered: 2011-08-04
Posts: 29

MulticoreBSP on Windows using Code::Blocks

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() );

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

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

    bsp_init( &spmd, argc, argv );

    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.


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

Albert-Jan Yzelman
Registered: 2011-08-04
Posts: 29

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).


Board footer

Powered by FluxBB