Friday, February 15, 2019

Digest for comp.lang.c++@googlegroups.com - 21 updates in 4 topics

rgladkik@sfu.ca: Feb 15 02:43PM -0800

I have the following struct:
 
 
struct NonlocalBonds {
std::vector<unsigned int> k;
unsigned int l;
 
unsigned int bond = 0;
bond ^= 1<<k;
 
unsigned int operator()(unsigned int i, unsigned int j) const {
assert(j > i);
 
if ((j-i) % 4 != 0 || (j-i) / 4 != l)
return k.end();
 
if ((i-2) % 4 != 0 || std::find(k.begin(), k.end(), (i-2) / 4) == k.end())
return k.end();
 
return ((1-2 / 4);
}
};
 
 
Where k and l are contained within a json output file, and are shown below:
 
"nonlocal_bonds": {
"k": [0, 4, 9, 11, 16, 18, 23, 27, 29, 32, 35, 38, 41, 45, 47, 50, 52, 56],
"l": 5
},
 
 
I am using i and j, which are unsigned ints whose values are specified in another function, to calculate l and k from the expressions (j-i) / 4 and (i-2) / 4). If the calculated l and k are matched with the l and k from my output file, I want to return the k that matched with the value of k in the output file. Then, I want to do bond ^= 1<<k on the returned k.
 
I know there are lots of errors in here, and I need help.
 
I think I am supposed to be returning std::find(k.begin(), k.end(), (i-2) / 4)) - k.end() or something, and the type of operator() is probably wrong, and I don't know how to tell "bond" that the k in this equation is the returned value.
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Feb 14 03:34PM -0800

On 2/14/2019 2:07 PM, Paavo Helde wrote:
 
> std::shared_mutex appears to call AcquireSRWLockShared() Windows SDK
> function et al.
 
> Don't have a suitable gcc at hand at the moment, maybe later.
 
Okay. I just tested it against a raw SRW Windows lock in the following code:
 
https://pastebin.com/raw/HgYzCDSQ
(please try it...)
 
My algorithm still beats it very badly. Mine takes around 34 seconds
ish, while Windows 10 SRW takes around 122 ish seconds.
 
My algorithm kind of slaughters it.
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Feb 14 03:41PM -0800

On 2/14/2019 2:13 PM, Ian Collins wrote:
> shared.m_state = 160000000
 
> $ g++ --version
> g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
 
Thanks Ian. My algorithm also "destroys" Windows SRW on my end. Fwiw
here is the code, _beware_ it needs windows.h:
 
https://pastebin.com/raw/HgYzCDSQ
 
Wow. Perhaps, my experimental read/write mutex is actually worth
something. :^)
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Feb 14 07:44PM -0800

On 2/14/2019 12:57 PM, Chris M. Thomasson wrote:
 
> https://pastebin.com/raw/xCBHY9qd
 
> Both of them work, and have different ways to gain write access. One is
> using a "fast" semaphore, one is using the "fast" mutex.
 
Wrt your blog, you should put up both versions for clarity. Add the one
from my crude benchmark code:
 
https://pastebin.com/raw/xCBHY9qd
 
It is performing well against std::shared_mutex. Also, it should
outperform the other one that you currently have on there.
 
The difference is in the way write access is acquire and released, take
a close look.
 
 
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Feb 14 07:44PM -0800

On 2/14/2019 1:11 PM, Melzzzzz wrote:
> On 2019-02-14, Chris M. Thomasson <invalid_chris_thomasson_invalid@invalid.com> wrote:
>> On 2/14/2019 9:47 AM, mvorbrodt@gmail.com wrote:
>>> On Thursday, February 14, 2019 at 2:03:43 AM UTC-5, Chris M. Thomasson wrote:
[...]
> ./beat1 174.65s user 109.39s system 385% cpu 1:13.68 total
> ~/.../bmaxa_data/examples >>> icpc -v
> icpc version 19.0.0.120 (gcc version 8.2.1 compatibility)
 
Thanks Melzzzzz.
Melzzzzz <Melzzzzz@zzzzz.com>: Feb 15 05:35AM

>> ~/.../bmaxa_data/examples >>> icpc -v
>> icpc version 19.0.0.120 (gcc version 8.2.1 compatibility)
 
> Thanks Melzzzzz.
Hm, when using clang's libc++ shared_mutex case won't finish even after
17 minutes ;)
 
--
press any key to continue or any other to quit...
Paavo Helde <myfirstname@osa.pri.ee>: Feb 15 07:39AM +0200

On 15.02.2019 1:34, Chris M. Thomasson wrote:
 
> My algorithm still beats it very badly. Mine takes around 34 seconds
> ish, while Windows 10 SRW takes around 122 ish seconds.
 
These numbers looks so bad like they were from a build with no
optimizations, but you wouldn't ever measure performance on a
non-optimized build, would you.
 
On my machine both times are below 20 seconds.
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Feb 15 01:00PM -0800

On 2/14/2019 9:35 PM, Melzzzzz wrote:
 
>> Thanks Melzzzzz.
> Hm, when using clang's libc++ shared_mutex case won't finish even after
> 17 minutes ;)
 
Really!?!?!, seriously, WTF! Did it just deadlock? Is there any CPU
activity on the process during this 17 minutes? My algorithm works fine,
and was verified with Relacy Race Detector multiple times.
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Feb 15 01:09PM -0800

On 2/14/2019 9:39 PM, Paavo Helde wrote:
> optimizations, but you wouldn't ever measure performance on a
> non-optimized build, would you.
 
> On my machine both times are below 20 seconds.
 
Just MSVC release mode with /Ox. So far, I cannot get shared_mutex or
SRW to beat my code, on my machine.
Melzzzzz <Melzzzzz@zzzzz.com>: Feb 15 09:15PM


> Really!?!?!, seriously, WTF! Did it just deadlock? Is there any CPU
> activity on the process during this 17 minutes? My algorithm works fine,
> and was verified with Relacy Race Detector multiple times.
There is CPU activity but look:
~/.../bmaxa_data/examples >>> clang -stdlib=libc++ -std=c++17 -Wall -O3 -march=native -pthread beat.cpp -o beat -lc++
~/.../bmaxa_data/examples >>> time ./beat
msec = 1159
shared.m_state = 1600000
 
 
Fin!
./beat 0.87s user 0.29s system 470% cpu 0.247 total
~/.../bmaxa_data/examples >>> vim beat.cpp
~/.../bmaxa_data/examples >>> clang -stdlib=libc++ -std=c++17 -Wall -O3 -march=native -pthread beat.cpp -o beat -lc++
~/.../bmaxa_data/examples >>> time ./beat
msec = 53918
shared.m_state = 1600000
 
 
Fin!
./beat 29.97s user 23.95s system 430% cpu 12.534 total
 
 
--
press any key to continue or any other to quit...
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Feb 15 01:29PM -0800

On 2/15/2019 1:15 PM, Melzzzzz wrote:
> shared.m_state = 1600000
 
> Fin!
> ./beat 29.97s user 23.95s system 430% cpu 12.534 total
 
Wait a minute. Did mine win our lose here? I am not sure what the
timings for:
 
msec = 1159
 
and
 
msec = 53918
 
map to. This is my fault because I am not showing the user what test
they are running! Bad. It is not showing the user if CT_TEST_FAST_MUTEX
is defined or not. Sorry. ;^o
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Feb 15 01:31PM -0800

On 2/15/2019 1:29 PM, Chris M. Thomasson wrote:
>> ~/.../bmaxa_data/examples >>> time ./beat
>> msec = 53918
>> shared.m_state = 1600000
[...]
 
^^^^^^^^^^^^^^
 
Ahhh, you reduced the number of iterations. Nice! Okay.
Melzzzzz <Melzzzzz@zzzzz.com>: Feb 15 09:37PM

>> ./beat 29.97s user 23.95s system 430% cpu 12.534 total
 
> Wait a minute. Did mine win our lose here? I am not sure what the
> timings for:
 
Yours is 1159.
 
 
--
press any key to continue or any other to quit...
Robert Wessel <robertwessel2@yahoo.com>: Feb 14 05:29PM -0600

On Thu, 14 Feb 2019 13:14:05 -0800 (PST), Paul <pepstein5@gmail.com>
wrote:
 
>> }
 
>> return 0;
>> }
 
(...)
>For example, 11795/25000 is different to 0.47184 which is 11796/25000
>My guess is that this is a typo and that you meant to say unique + 0.0
>Is this correct? I understand that you are casting to double here.
 
 
Yes, a typo. I was actually intending to multiply by 1.0 to get the
conversion.
Ralf Fassel <ralfixx@gmx.de>: Feb 15 11:13AM +0100

* Robert Wessel <robertwessel2@yahoo.com>
| >My guess is that this is a typo and that you meant to say unique + 0.0
| >Is this correct? I understand that you are casting to double here.
 
| Yes, a typo. I was actually intending to multiply by 1.0 to get the
| conversion.
 
...wouldn't double(unique) do the trick?
 
R'
Juha Nieminen <nospam@thanks.invalid>: Feb 15 10:15AM

> For example, 11795/25000 is different to 0.47184 which is 11796/25000
> My guess is that this is a typo and that you meant to say unique + 0.0
> Is this correct? I understand that you are casting to double here.
 
You needed to quote 200 lines of the original post to write this?
 
Editing the quote is allowed, you know?
 
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Robert Wessel <robertwessel2@yahoo.com>: Feb 15 09:27AM -0600

On Fri, 15 Feb 2019 11:13:03 +0100, Ralf Fassel <ralfixx@gmx.de>
wrote:
 
 
>| Yes, a typo. I was actually intending to multiply by 1.0 to get the
>| conversion.
 
>...wouldn't double(unique) do the trick?
 
 
It would, although my example happened to be C, not C++. A C-style
cast would have worked, but I try to avoid those when not necessary.
jameskuyper@alumni.caltech.edu: Feb 15 07:56AM -0800

> On Fri, 15 Feb 2019 11:13:03 +0100, Ralf Fassel <ralfixx@gmx.de>
> wrote:
 
> >* Robert Wessel <robertwessel2@yahoo.com>
...
 
> >...wouldn't double(unique) do the trick?
 
> It would, although my example happened to be C, not C++. A C-style
> cast would have worked, but I try to avoid those when not necessary.
 
Avoiding a cast when the conversion will happen automatically is a very
good idea - the conversions that occur implicitly are the safest ones.
Changing the code by multiplying or dividing by 1, or by adding or
subtracting 0, for the sole purpose of causing a conversion without a
cast, makes your code more confusing. If you want to cause a conversion,
use the construct whose sole purpose is to cause a conversion. The basic
arithmetic operations are not such constructs.
Geoff <geoff@invalid.invalid>: Feb 15 10:41AM -0800

On Fri, 15 Feb 2019 10:15:47 +0000 (UTC), Juha Nieminen
 
>You needed to quote 200 lines of the original post to write this?
 
>Editing the quote is allowed, you know?
 
He used Goggle Groups. You expected better?
jameskuyper@alumni.caltech.edu: Feb 15 10:55AM -0800

On Friday, February 15, 2019 at 1:41:44 PM UTC-5, Geoff wrote:
 
> >You needed to quote 200 lines of the original post to write this?
 
> >Editing the quote is allowed, you know?
 
> He used Goggle Groups. You expected better?
 
I'm often use Google Groups, and I routinely edit quoted material to
trim out anything not needed to provide adequate context for my
response. So, while I don't expect better, it's certainly feasible to do
better.
Nikki Locke <nikki@trumphurst.com>: Feb 14 11:23PM

Available C++ Libraries FAQ
 
URL: http://www.trumphurst.com/cpplibs/
 
This is a searchable list of libraries and utilities (both free
and commercial) available to C++ programmers.
 
If you know of a library which is not in the list, why not fill
in the form at http://www.trumphurst.com/cpplibs/cppsub.php
 
Maintainer: Nikki Locke - if you wish to contact me, please use the form on the website.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: