[OpenMP] Parameter packs

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[OpenMP] Parameter packs

via cfe-dev
Should this compile?

#include <tuple>

constexpr std::size_t N = 100;

double A[N];

template<typename ...Args>
void loop(Args ...args) {
#pragma omp parallel firstprivate(args...)
  for (std::size_t i = 0; i < N; ++i) {
    A[i] = (i + ... + args);
  }
}

int main(void) {
  std::apply([] (const auto & ...args) { loop(args...); },
                 std::tuple<int, double, float>(10, 2.6, 3.4));
  std::apply([] (const auto & ...args) { loop(args...); },
                 std::tuple<int, long, char, double, short>(10, 100, 'b', 2.6, 3));
  return 0;
}

clang++ errors with:

firstprivate.cpp:10:39: error: expected ',' or ')' in 'firstprivate' clause
#pragma omp parallel firstprivate(args...)
                                      ^
firstprivate.cpp:10:39: error: expected expression
2 errors generated.

g++ gives a similar error.  I was not terribly surprised by this.
However, it sure would be nice if it worked.

                      -David
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Openmp-dev] [OpenMP] Parameter packs

via cfe-dev
The OpenMP specification has the following restriction:

"Variadic parameter packs cannot be expanded into a directive or its clauses except as part of an expression argument to be evaluated by the base language, such as into a function call inside an if clause."

The language committee has some discussions on it in the last face-to-face meeting.  We will look into relaxing this restriction to provide better usage with C++ templates.

Kelvin


"Openmp-dev" <[hidden email]> wrote on 2018/10/15 10:45:30 AM:

> From: David Greene via Openmp-dev <[hidden email]>

> To: "[hidden email]" <[hidden email]>, "openmp-
> [hidden email]" <[hidden email]>

> Date: 2018/10/15 10:46 AM
> Subject: [Openmp-dev] [OpenMP] Parameter packs
> Sent by: "Openmp-dev" <[hidden email]>
>

> Should this compile?
>
> #include <tuple>
>
> constexpr std::size_t N = 100;
>
> double A[N];
>
> template<typename ...Args>
> void loop(Args ...args) {
> #pragma omp parallel firstprivate(args...)
>   for (std::size_t i = 0; i < N; ++i) {
>     A[i] = (i + ... + args);
>   }
> }
>
> int main(void) {
>   std::apply([] (const auto & ...args) { loop(args...); },
>                  std::tuple<int, double, float>(10, 2.6, 3.4));
>   std::apply([] (const auto & ...args) { loop(args...); },
>                  std::tuple<int, long, char, double, short>(10, 100,
> 'b', 2.6, 3));
>   return 0;
> }
>
> clang++ errors with:
>
> firstprivate.cpp:10:39: error: expected ',' or ')' in 'firstprivate' clause
> #pragma omp parallel firstprivate(args...)
>                                       ^
> firstprivate.cpp:10:39: error: expected expression
> 2 errors generated.
>
> g++ gives a similar error.  I was not terribly surprised by this.
> However, it sure would be nice if it worked.
>
>                       -David
> _______________________________________________
> Openmp-dev mailing list
> [hidden email]
>
https://urldefense.proofpoint.com/v2/url?
> u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_openmp-2Ddev&d=DwIGaQ&c=jf_iaSHvJObTbx-
> siA1ZOg&r=yebGUrvFJWJ7GtM9woczVA&m=2EY3U33AkbJ5xLUmwJHWUGdi3b2YZ6eYCasI_AnITmo&s=5ovzADp3MTFkziuO0pgVRB4f6eqcyYS8Rujz1vEheF0&e=
>


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Openmp-dev] [OpenMP] Parameter packs

via cfe-dev
Good to hear.  Is it technically difficult to do in clang?  If not,
would an experimental implementation help the committee?

                               -David

Kelvin Li via Openmp-dev <[hidden email]> writes:

> The OpenMP specification has the following restriction:
>
> "Variadic parameter packs cannot be expanded into a directive or its
> clauses except as part of an expression argument to be evaluated by
> the base language, such as into a function call inside an if clause."
>
> The language committee has some discussions on it in the last
> face-to-face meeting. We will look into relaxing this restriction to
> provide better usage with C++ templates.
>
> Kelvin
>
> "Openmp-dev" <[hidden email]> wrote on 2018/10/15
> 10:45:30 AM:
>
>> From: David Greene via Openmp-dev <[hidden email]>
>> To: "[hidden email]" <[hidden email]>, "openmp-
>> [hidden email]" <[hidden email]>
>> Date: 2018/10/15 10:46 AM
>> Subject: [Openmp-dev] [OpenMP] Parameter packs
>> Sent by: "Openmp-dev" <[hidden email]>
>>
>> Should this compile?
>>
>> #include <tuple>
>>
>> constexpr std::size_t N = 100;
>>
>> double A[N];
>>
>> template<typename ...Args>
>> void loop(Args ...args) {
>> #pragma omp parallel firstprivate(args...)
>> for (std::size_t i = 0; i < N; ++i) {
>> A[i] = (i + ... + args);
>> }
>> }
>>
>> int main(void) {
>> std::apply([] (const auto & ...args) { loop(args...); },
>> std::tuple<int, double, float>(10, 2.6, 3.4));
>> std::apply([] (const auto & ...args) { loop(args...); },
>> std::tuple<int, long, char, double, short>(10, 100,
>> 'b', 2.6, 3));
>> return 0;
>> }
>>
>> clang++ errors with:
>>
>> firstprivate.cpp:10:39: error: expected ',' or ')' in 'firstprivate'
> clause
>> #pragma omp parallel firstprivate(args...)
>> ^
>> firstprivate.cpp:10:39: error: expected expression
>> 2 errors generated.
>>
>> g++ gives a similar error. I was not terribly surprised by this.
>> However, it sure would be nice if it worked.
>>
>> -David
>> _______________________________________________
>> Openmp-dev mailing list
>> [hidden email]
>> https://urldefense.proofpoint.com/v2/url?
>>
> u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_openmp-2Ddev&d=DwIGaQ&c=jf_
> iaSHvJObTbx-
>>
> siA1ZOg&r=yebGUrvFJWJ7GtM9woczVA&m=2EY3U33AkbJ5xLUmwJHWUGdi3b2YZ6eYCasI_
> AnITmo&s=5ovzADp3MTFkziuO0pgVRB4f6eqcyYS8Rujz1vEheF0&e=
>>
>
>
> _______________________________________________
> Openmp-dev mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Openmp-dev] [OpenMP] Parameter packs

via cfe-dev
In reply to this post by via cfe-dev
On 10/15/2018 05:03 PM, Kelvin Li via Openmp-dev wrote:
> The OpenMP specification has the following restriction:
>
> "Variadic parameter packs cannot be expanded into a directive or its
> clauses except as part of an expression argument to be evaluated by the
> base language, such as into a function call inside an if clause."
>

Glad to see that this is covered by spec text. Unfortunately, searching
the document for "parameter pack" has no match, because of the line
break between the two words :/

> The language committee has some discussions on it in the last
> face-to-face meeting.  We will look into relaxing this restriction to
> provide better usage with C++ templates.
>
> Kelvin
>
>
> "Openmp-dev" <[hidden email]> wrote on 2018/10/15
> 10:45:30 AM:
>
>  > From: David Greene via Openmp-dev <[hidden email]>
>  > To: "[hidden email]" <[hidden email]>, "openmp-
>  > [hidden email]" <[hidden email]>
>  > Date: 2018/10/15 10:46 AM
>  > Subject: [Openmp-dev] [OpenMP] Parameter packs
>  > Sent by: "Openmp-dev" <[hidden email]>
>  >
>  > Should this compile?
>  >
>  > #include <tuple>
>  >
>  > constexpr std::size_t N = 100;
>  >
>  > double A[N];
>  >
>  > template<typename ...Args>
>  > void loop(Args ...args) {
>  > #pragma omp parallel firstprivate(args...)
>  >   for (std::size_t i = 0; i < N; ++i) {
>  >     A[i] = (i + ... + args);
>  >   }
>  > }
>  >
>  > int main(void) {
>  >   std::apply([] (const auto & ...args) { loop(args...); },
>  >                  std::tuple<int, double, float>(10, 2.6, 3.4));
>  >   std::apply([] (const auto & ...args) { loop(args...); },
>  >                  std::tuple<int, long, char, double, short>(10, 100,
>  > 'b', 2.6, 3));
>  >   return 0;
>  > }
>  >
>  > clang++ errors with:
>  >
>  > firstprivate.cpp:10:39: error: expected ',' or ')' in 'firstprivate'
> clause
>  > #pragma omp parallel firstprivate(args...)
>  >                   ^
>  > firstprivate.cpp:10:39: error: expected expression
>  > 2 errors generated.
>  >
>  > g++ gives a similar error.  I was not terribly surprised by this.
>  > However, it sure would be nice if it worked.
>  >
>  >   -David
>  > _______________________________________________
>  > Openmp-dev mailing list
>  > [hidden email]
>  > https://urldefense.proofpoint.com/v2/url?
>  >
> u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_openmp-2Ddev&d=DwIGaQ&c=jf_iaSHvJObTbx-
>  >
> siA1ZOg&r=yebGUrvFJWJ7GtM9woczVA&m=2EY3U33AkbJ5xLUmwJHWUGdi3b2YZ6eYCasI_AnITmo&s=5ovzADp3MTFkziuO0pgVRB4f6eqcyYS8Rujz1vEheF0&e=
>  >
>
>
>
> _______________________________________________
> Openmp-dev mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev
>

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Openmp-dev] [OpenMP] Parameter packs

via cfe-dev
In reply to this post by via cfe-dev
I do not think it is very difficult.  The experts on the list can correct me if there
are some complications involved.

A reference implementation can always help the standardization process.

Kelvin


David Greene <[hidden email]> wrote on 2018/10/15 11:08:49 AM:

> From: David Greene <[hidden email]>

> To: Kelvin Li <[hidden email]>
> Cc: "[hidden email]" <[hidden email]>, Openmp-dev
> <[hidden email]>, "[hidden email]"
> <[hidden email]>

> Date: 2018/10/15 11:15 AM
> Subject: Re: [Openmp-dev] [OpenMP] Parameter packs
>

> Good to hear.  Is it technically difficult to do in clang?  If not,
> would an experimental implementation help the committee?
>
>                                -David
>
> Kelvin Li via Openmp-dev <[hidden email]> writes:
>
> > The OpenMP specification has the following restriction:
> >
> > "Variadic parameter packs cannot be expanded into a directive or its
> > clauses except as part of an expression argument to be evaluated by
> > the base language, such as into a function call inside an if clause."
> >
> > The language committee has some discussions on it in the last
> > face-to-face meeting. We will look into relaxing this restriction to
> > provide better usage with C++ templates.
> >
> > Kelvin
> >
> > "Openmp-dev" <[hidden email]> wrote on 2018/10/15
> > 10:45:30 AM:
> >
> >> From: David Greene via Openmp-dev <[hidden email]>
> >> To: "[hidden email]" <[hidden email]>, "openmp-
> >> [hidden email]" <[hidden email]>
> >> Date: 2018/10/15 10:46 AM
> >> Subject: [Openmp-dev] [OpenMP] Parameter packs
> >> Sent by: "Openmp-dev" <[hidden email]>
> >>
> >> Should this compile?
> >>
> >> #include <tuple>
> >>
> >> constexpr std::size_t N = 100;
> >>
> >> double A[N];
> >>
> >> template<typename ...Args>
> >> void loop(Args ...args) {
> >> #pragma omp parallel firstprivate(args...)
> >> for (std::size_t i = 0; i < N; ++i) {
> >> A[i] = (i + ... + args);
> >> }
> >> }
> >>
> >> int main(void) {
> >> std::apply([] (const auto & ...args) { loop(args...); },
> >> std::tuple<int, double, float>(10, 2.6, 3.4));
> >> std::apply([] (const auto & ...args) { loop(args...); },
> >> std::tuple<int, long, char, double, short>(10, 100,
> >> 'b', 2.6, 3));
> >> return 0;
> >> }
> >>
> >> clang++ errors with:
> >>
> >> firstprivate.cpp:10:39: error: expected ',' or ')' in 'firstprivate'
> > clause
> >> #pragma omp parallel firstprivate(args...)
> >> ^
> >> firstprivate.cpp:10:39: error: expected expression
> >> 2 errors generated.
> >>
> >> g++ gives a similar error. I was not terribly surprised by this.
> >> However, it sure would be nice if it worked.
> >>
> >> -David
> >> _______________________________________________
> >> Openmp-dev mailing list
> >> [hidden email]
> >>
https://urldefense.proofpoint.com/v2/url?
> >>
> >
> u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_openmp-2Ddev&d=DwIGaQ&c=jf_
> > iaSHvJObTbx-
> >>
> > siA1ZOg&r=yebGUrvFJWJ7GtM9woczVA&m=2EY3U33AkbJ5xLUmwJHWUGdi3b2YZ6eYCasI_
> > AnITmo&s=5ovzADp3MTFkziuO0pgVRB4f6eqcyYS8Rujz1vEheF0&e=
> >>
> >
> >
> > _______________________________________________
> > Openmp-dev mailing list
> > [hidden email]
> >
https://urldefense.proofpoint.com/v2/url?
> u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_openmp-2Ddev&d=DwIFAw&c=jf_iaSHvJObTbx-
> siA1ZOg&r=yebGUrvFJWJ7GtM9woczVA&m=mjlomL7F-
> du_g3pBBm4fwgsDuDM41jGNr3ndgflnJfQ&s=gSADVaIIvC4wmZn4vCIKIvoa1jQ9wps2fbpp91-
> T25c&e=
>


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev