O'Reilly logo

C++ Multithreading Cookbook by Milos Ljumovic

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Turning on to a parallel approach

Now, we want to add concurrency to the same example. Note that we've designed the CSchwefel class for such a task, because beside the Evaluate method, everything remains the same! Again, the power of object-oriented programming saves us a lot of coding and time.

Getting ready

Make sure that Visual Studio is up and running.

How to do it...

Now, let's create the CSchwefelMT class and explain its structure. Perform the following steps:

  1. Open Solution Explorer and open the file stdafx.h. Copy and paste the following code to it:
    #pragma once
    
    #include "targetver.h"
    
    #include <stdio.h>
    #include <tchar.h>
    #include <Windows.h>
    #include <cfloat>
    #include <time.h>
    #include <omp.h>
    
    #include "Schwefel.h"
    #include "SchwefelMT.h"
  2. Open ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required