This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[libstdc++-v3 parallel mode] Why is not std::transform executed in parallel by default?


Hi,

I'm enjoying the novel libstdc++ parallel mode, and I have some
questions about it:

  Does a user need to specify __gnu_parallel::parallel_balanced (or
  other choice in _Parallelism) explicitly to execute std::transform
  (and __gnu_parallel::transform) in parallel?
  Is it an intended (desired) behavior of the parallel mode?
  Why is not std::transform executed in parallel by default when
  -D_GLIBCXX_PARALLEL is specified?

The situation is as follows.  I wanted to execute the following
program (i.e., std::transform) in parallel, and I tried the subsequent
three things 1)--3). Then, only 3) succeeded in the parallel
execution, and 1) and 2) failed (they were executed by the sequential
code).
# compiled with g++ of release 3.4.2 and the svn (r140330)

A piece of code:
  int querying(const vector<string> &db, const string &qr)
  {
    vector<int> cs(n);
    transform(db.begin(), db.end(), cs.begin(), Query(qr));
    return accumulate(cs.begin(), cs.end(), 0, plus<int>());
  }

What I did:
1) just compiled the program with the following options:

   g++-X.X.X querying.cpp -o querying -O3 -D_GLIBCXX_PARALLEL -fopenmp -march=native

2) replaced the invocation of the std::transform with the following
   parallel implementation explicitly, and compiled it with the same
   option as above.

   __gnu_parallel::transform(db.begin(), db.end(), cs.begin(), Query(qr));

3) replaced explicitly the invocation of the std::transform with the
   following parallel implementation with the last argument, and
   compiled it with the same option as above.

   __gnu_parallel::transform(db.begin(), db.end(), cs.begin(), Query(qr), __gnu_parallel::parallel_balanced);



BTW, when the default parameter value
__gnu_parallel::parallel_balanced of the last parameter of
transform1_switch (parallel/algo.h) is put into the prototype
declaration of transform1_switch (parallel/algorithmfwd.h),
std::transform is executed in parallel by default (when
-D_GLIBCXX_PARALLEL is specified).

  Why is the default value specified not in the prototype
  declaration but in the definition?

Since the prototype without the default value is found earlier than
the definition with the default value, g++ determines that
transform1_switch does not have the default value. This situation
occurs also in other 'XXX_switch'es.

Best regards,
Kento Emoto




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]