Search
Items tagged with: cplusplus
One of the reasons I keep dropping hints about #perlffi , #pdl and #openmp is that one can literally have five multithreading frameworks in the same #perl application of a master process: 1) PDL, and FFI intefacing with 2) #Fortran coarrays, 3) Fortran openmp, 4) #c openmp and 5) #cplusplus #openmp. All these frameworks can share memory addresses for array and vector objects, and #perl aided by #PerlAlien makes the authoring of the high-level code a pleasure ! https://hgpu.org/?p=29403
submitted by /u/ReplacementSlight413
[link] [comments]
Optimizing the Weather Research and Forecasting Model with OpenMP Offload and Codee
Currently, the Weather Research and Forecasting model (WRF) utilizes shared memory (OpenMP) and distributed memory (MPI) parallelisms. To take advantage of GPU resources on the Perlmutter supercompβ¦hgpu.org
https://github.com/chrisarg/task-memmanager
GitHub - chrisarg/task-memmanager
Contribute to chrisarg/task-memmanager development by creating an account on GitHub.GitHub
Direct (non-LinkedIn-shortened) link: https://catonmat.net/ftp/perl1line.txt
Iβm also pleased that its author ranked Perl as one of his top 5 best #programming languages: https://catonmat.net/5-best-programming-languages
1. #C / #Clang
2. #PHP
3. #Perl
4. #GoLang
5. #JavaScript (but only version 1 circa 1995 plus #jQuery)
His 5 worst? https://catonmat.net/5-worst-programming-languages
1. #Haskell
2. #Rust / #RustLang
3. #CPlusPlus
4. #Python
5. modern #JavaScript
βMy only metric... is time to get things done and ship to customers.β
Top 5 Best Programming Languages
This is the reverse post of my highly popular Top 5 Worst Programming Languages post. My only metric for a good programming language is time to get things done and ship to customers. I don't care about anything else.catonmat.net
To demonstrate the power of C++, I have reimplemented the algorithm in a single file using the built-in metaprogramming capabilities of C++. No more manual source generation; no more Python!
#[url=https://infosec.exchange/tags/include]include[/url] <stdio.h><br>#[url=https://infosec.exchange/tags/include]include[/url] <stdint.h><br>#[url=https://infosec.exchange/tags/include]include[/url] <stdlib.h><br>#[url=https://infosec.exchange/tags/include]include[/url] <limits><br><br>using T = uint8_t;<br><br>namespace {<br> template<T><br> void do_check(T, const char *, const char *);<br><br> template<><br> void do_check<0>(T n, const char *msg_yes, const char *) {<br> if (n == 0) {<br> puts(msg_yes);<br> }<br> }<br><br> template<T limit><br> void do_check(T n, const char *msg_yes, const char *msg_no) {<br> do_check<limit - 1>(n, msg_no, msg_yes);<br> if (n == limit) {<br> puts(msg_yes);<br> }<br> }<br>}<br><br>static void check(T n) {<br> do_check<std::numeric_limits<T>::max()>(n, "odd", "even");<br>}<br><br>int main(int, char **argv) {<br> check(atoi(argv[1]));<br>}<br>
Compiler explorer: https://godbolt.org/z/434bPMP3M
To generate the comparisons, we use template metaprogramming. However, there are no template loops. C++ templates can be classified as an esoteric purely functional programming language, so we have to use pattern matching and recursion.
The do_check<N>
template generates comparisons up to N. Our base case is do_check<0>
, which compares to 0 and does nothing else. The general (inductive) case calls do_check<N - 1>
and then compares to N.
It is interesting to look at the generated code. G++ translates the algorithm faithfully, if slightly chaotically (look at the order of labels and comparisons in the source; it jumps all over the place). Clang, on the other hand, implements one of the optimizations suggested by @gkemp. It fills a big array with messages (messages[256] = { "even", "odd", "even", "odd", ... }
) and then outputs messages[n]
(there is only a single call to puts
in the generated assembler code).
This covers numbers from 0 to 255 (the range of uint8_t
). We can extend the range by switching to using T = uint16_t
, although doing so naively runs into the following error:
x.cc:21:28: fatal error: template instantiation depth exceeds maximum of 900 (use β-ftemplate-depth=β to increase the maximum)<br>
Fortunately it tells us how to fix it and with
g++ -ftemplate-depth=65536
we are right back in business. Well, after waiting 2Β½ minutes for the compilation to finish, that is. (Clang is less fortunate: It crashes with a segmentation fault after exhausting the available stack space, at least on Compiler Explorer.)I haven't dared try T = uint32_t
yet.
Compiler Explorer - C++
using T = uint8_t; namespace { template void do_check(T, const char *, const char *); template<> void do_check<0>(T n, const char *msg_yes, const char *) { if (n == 0) { puts(msg_yes); } } temβ¦godbolt.org
Would be nice to have a benchmark set of problems to compare #copilot 's performance across languages.
Programmers, developers, coders!
Let's get to know each other in Mastodon
π» Make a repost, write what you do and where you are from
π€ Subscribe each other
π°οΈ Let this signal pass through all obstacles
Let the wave flow! Halt and Catch Fire!
#programming #mastodon #developer #programmer #coding #code #introduction #community #dev #gamedev #webdev #linux #android #ios #csharp #cplusplus #java #javascript #ai #clouds #windows #socialmedia #world #introductions