Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8371369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:08:46+00:00 2026-06-09T14:08:46+00:00

In Intel Cilk Plus extension there’s this keyword cilk_for (or _Cilk_for actually). It’s like

  • 0

In Intel Cilk Plus extension there’s this keyword cilk_for (or _Cilk_for actually). It’s like the keyword for, but more restrictive and its iterations run in parallel. I wrote a convenience macro in the spirit of BOOST_FOREACH, which uses cilk_for internally. Can you see any problems with the following implementation?

#pragma once

#include <iterator>
#include <boost/preprocessor/cat.hpp>
#include <cilk/cilk.h>

#define cilk_foreach(_decl_var_, _expr_range_) \
    CILK_FOREACH_I(_decl_var_, _expr_range_, __COUNTER__)

#define CILK_FOREACH_I(_decl_var_, _expr_range_, _id_)               \
    CILK_FOREACH_II(_decl_var_,                                      \
                    _expr_range_,                                    \
                    BOOST_PP_CAT(_range_3s236dw221GyVcf46_, _id_),   \
                    BOOST_PP_CAT(_end_5Y60u42bIp7DZd88f2c_, _id_),   \
                    BOOST_PP_CAT(_itr_6V970q8n4Etv0i8bf50_, _id_),   \
                    BOOST_PP_CAT(_continue_4rtWH641r5cXqU_, _id_))

#define CILK_FOREACH_II(_decl_var_, _expr_range_, _range_, _end_, _itr_, _cont_) \
    auto&& _range_ = _expr_range_;                                               \
    auto   _end_   = std::end(_range_);                                          \
                                                                                 \
    cilk_for (auto _itr_ = std::begin(_range_); _itr_ != _end_; ++_itr_)         \
        if (auto _cont_ = true)                                                  \
            for (_decl_var_ = *_itr_; _cont_; _cont_ = false)

You would use it like so:

std::vector<int> values (10);

cilk_foreach (auto& value , values)
{
    value += 123;
}

EDIT

template <typename T>
struct Wrap
{
    T& data;

    explicit Wrap(T&& data)
        : data (data)
    {}

    operator bool() const
    {
        return true;
    }
};

template <typename T>
Wrap<T> wrap(T&& data)
{
    return Wrap<T>(std::forward<T>(data));
}

#define cilk_foreach(_decl_var_, _expr_range_) \
    CILK_FOREACH_I(_decl_var_, _expr_range_, __COUNTER__)

#define CILK_FOREACH_I(_decl_var_, _expr_range_, _id_)              \
                                                                    \
    CILK_FOREACH_II(_decl_var_,                                     \
                    _expr_range_,                                   \
                    BOOST_PP_CAT(_range_3s236dw221GyVcf46_, _id_),  \
                    BOOST_PP_CAT(_itr_6V970q8n4Etv0i8bf50_, _id_),  \
                    BOOST_PP_CAT(_continue_4rtWH641r5cXqU_, _id_))

#define CILK_FOREACH_II(_decl_var_, _expr_range_, _range_, _itr_, _cont_)  \
                                                                           \
    if (auto _range_ = wrap(_expr_range_))                                 \
        cilk_for (auto _itr_  = std::begin(_range_.data);                  \
                       _itr_ != std::end  (_range_.data);                  \
                     ++_itr_)                                              \
            if (auto _cont_ = true)                                        \
                for (_decl_var_ = *_itr_; _cont_; _cont_ = false)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:08:47+00:00Added an answer on June 9, 2026 at 2:08 pm

    You should probably read this: C++ Boost: Any gotchas with BOOST_FOREACH?

    One obvious problem is that your marco doesn’t expand into something that has the lexical type it looks like it has. As an example, consider

    if(condition)
        cilk_foreach (auto& value , values) {
            //stuff
        }
    

    or even worse

    if(condition)
        cilk_foreach (auto& value , values) 
            // one-line stuff
    else
        // other stuff
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any library like Intel TBB in Java which support Parallelism.
With Intel's launch of a Hexa-Core(6) processor for the desktop, it looks like we
I read the Intel manual and found there is a lock prefix for instructions,
I am impressed with intel thread building blocks. I like how i should write
In the Intel documentation manuals, I see references to 00+ multiple places, but no
Are there any Intel AVX intrinsics library out? I'm looking for something similar as
have Intel Core i7 laptop with 8 GB ram. This is my first time
The Intel Architecture's Developer's Manual (Vol3A, Section 8-26), says: The Pentium processor and more
I've built an Intel-syntax assembly parser in JavaScript. Now I want to do more:
I work with intel parallel studio 2011 and I included: #include <cilk/cilk.h> which seemed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.