Dual core programming?

Hi i have a permutation program that i think would run faster if i used the 2 cores on my cpu, but after having a look around it seems confusing to grasp the idea of how i can acomplish this. Below is the code for my permutations, if someone could give me an example then it might be easier for me to understand, many thanks :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// next_permutation.cpp
// next_permutation : Change the order of the sequence to the
//                    next lexicograhic permutation.
// disable warning C4786: symbol greater than 255 character,
// okay to ignore
#pragma warning(disable: 4786)

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>

using namespace std ;

int main()
{
    const int VECTOR_SIZE = 20;

    // Define a template class vector of strings
    typedef vector<string> StrVector ;

    //Define an iterator for template class vector of strings
    typedef StrVector::iterator StrVectorIt ;

    //Define an ostream iterator for strings
    typedef ostream_iterator<string> StrOstreamIt;

    StrVector Pattern(VECTOR_SIZE) ;

    StrVectorIt start, end, it ;

    StrOstreamIt outIt(cout," ") ;

    start = Pattern.begin() ;   // location of first
                                // element of Pattern

    end = Pattern.end() ;       // one past the location last
                                // element of Pattern

    //Initialize vector Pattern  	
    Pattern[0]  = "TOM";
    Pattern[1]  = "DICK";
    Pattern[2]  = "HARRY";
    Pattern[3]  = "PAUL";
    Pattern[4]  = "PETER";
    Pattern[5]  = "STEVEN";
    Pattern[6]  = "JOHN";
    Pattern[7]  = "IAN";
    Pattern[8]  = "GEORGE";
    Pattern[9]  = "KEVIN";
    Pattern[10] = "SCOTT";
    Pattern[11] = "STUART";
    Pattern[12] = "BRIAN";
    Pattern[13] = "DAVID";
    Pattern[14] = "SEAN";
    Pattern[15] = "STEVIE";
    Pattern[16] = "MARK";
    Pattern[17] = "RYAN";
    Pattern[18] = "RUDOLF";
    Pattern[19] = "SANTA";

    

    // print content of Pattern
	cout  << "Pattern: " ;
    cout << "Before calling next_permutation:\n" << "Pattern: " ;
    for(it = start; it != end; it++)
        cout << *it << " " ;
    cout << "\n\n" ;

    // Generate all possible permutations

    cout << "After calling next_permutation:" << endl ;
    while ( next_permutation(start, end) )
    {
        copy(start, end, outIt) ;
        cout << endl ;
    }
	return 0;
}


Last edited on
thanks for the quick reply but there is only minor talk about it on that link. :)
The information to pick out is: threads, with options to express your wishes for running on more than one core.
What part of the code do you think would be fit for parallel execution?
Topic archived. No new replies allowed.