/**
*
* @file CNpThreadsBoostV1.cpp
*
* @author D. Mathieu, M. Laporte
*
* @date 23/09/2008
*
* @version 2.0
*
* @brief Calcul parallele de CNp
*
**/
#include <iostream>
#include <vector>
#include <sstream>
#include <boost/thread/thread.hpp>
#include <boost/tr1/functional.hpp> // ou <functional>
//#include "CstCodErr.h"
using namespace std;
using namespace boost;
//using namespace nsUtil; // KExcArg
namespace
{
enum { KExcArg = 253 }; // Erreur d'arguments de main()
void CNp (unsigned N, unsigned p, unsigned * pRes)
{
if (N == p)
{
*pRes = 1;
return;
}
if (p == 1)
{
*pRes = N;
return;
}
unsigned r1;
unsigned r2;
thread_group groupThreads;
groupThreads.create_thread (bind (CNp, N - 1, p - 1, & r1));
groupThreads.create_thread (bind (CNp, N - 1, p , & r2));
groupThreads.join_all ();
*pRes = r1 + r2;
} // CNp()
} // namespace
int main (int argc, char * argv [])
{
if (argc != 3)
{
cerr << "Usage : " << argv [0] << " <N> <p>\n";
return KExcArg;
}
unsigned N;
{
istringstream is (argv [1]);
is >> N;
}
unsigned p;
{
istringstream is (argv [2]);
is >> p;
}
cout << "C (" << N << ", " << p << ") = " << flush;
unsigned result;
thread thr (bind (CNp, N, p, & result));
thr.join ();
cout << result << '\n';
return 0;
} // main()