Vlad
In C?
fscanf
'''''''
Pavel
I don't have his username
You can open the chat with them, click on the avatar to open their profile and copy the username from it long pressing on the username). Otherwise you can just report writing the name that you've sent, should work I guess.
Vlad
No one has an idea?...
initialize it with .begin() .end() pair
Vlad
Or use std::move()
Shahar
Or use std::move()
Tried that one, IDE is yelling on that also: In template: no matching constructor for initialization of 'std::vector<std::pair<K2 *, V2 *>, std::allocator<std::pair<K2 *, V2 *>>>'
Shahar
initialize it with .begin() .end() pair
You mean, using insert method?
Vlad
You mean, using insert method?
Would work with emplace back as well
Vlad
.emplace_back(vec.begin(), vec.end());
PANKIA
Assembly language compiler pls
Vlad
Also it's offtopic a little bit here
PANKIA
U know like nasm or masm
Shahar
.emplace_back(vec.begin(), vec.end());
LOL, you know what was the problem? I had to do: shuffledQueue.emplace_back(sameKeyPairVector.second);
Vlad
It's a pair of vectors?
Vlad
ftw
Vlad
U know like nasm or masm
They are also assemblers
Anonymous
Hello
Shahar
wait what?
void ThreadContext::invokeShufflePhase() { if (thread_id_ == 0) // by convention - only thread-0 performs the shuffle phase {//IntermediatePair==std::pair<K2*, V2*> std::unordered_map<K2*, IntermediateVec> keyToVectorOfPairs;//IntermediateVec==std::vector<IntermediatePair> for (size_t i = 0; i < currentJobContext_.getNumOfThreads(); ++i){ // std::vector<std::pair<K2*, V2*>> sorted by K2 auto currIntermediateVec = currentJobContext_.getThreadContext(i).getIntermediateVec(); for(const auto& elem : currIntermediateVec){ keyToVectorOfPairs[elem.first].emplace_back(elem); } } auto shuffledQueue = currentJobContext_.getShuffledQueue(); // std::vector<std::vector<std::pair<K2*, V2*>>> for(const auto& sameKeyPairVector : keyToVectorOfPairs){ shuffledQueue.emplace_back(sameKeyPairVector.second); } } // else => you aren't thread-0, so go wait on barrier }
Vlad
They are also assemblers
You wouldn't believe it
Shahar
Well I completely lost it, tbh
The problem was that I tried inserting into shuffledQueue a mapping element (K2* -> std::vector of pairs) But the point is we want to insert into shuffledQueue a std::vector of pairs, hence we had to emplace_back the second field of each map's element
Anonymous
Hello everyone
Anonymous
Please need help again
Anonymous
Write a C program which is capable of transcribing any whole number into words. Ex: If the input is 21205, the output should be Twenty one thousand two hundred and five. It should also put commas to make the number more visible. For example: 21205 should also be written as 21,205.
Shahar
Well I completely lost it, tbh
Can I refactor this code without many copies?
Shahar
void ThreadContext::invokeShufflePhase() { if (thread_id_ == 0) // by convention - only thread-0 performs the shuffle phase {//IntermediatePair==std::pair<K2*, V2*> std::unordered_map<K2*, IntermediateVec> keyToVectorOfPairs;//IntermediateVec==std::vector<IntermediatePair> for (size_t i = 0; i < currentJobContext_.getNumOfThreads(); ++i){ // std::vector<std::pair<K2*, V2*>> sorted by K2 auto currIntermediateVec = currentJobContext_.getThreadContext(i).getIntermediateVec(); for(const auto& elem : currIntermediateVec){ keyToVectorOfPairs[elem.first].emplace_back(elem); } } auto shuffledQueue = currentJobContext_.getShuffledQueue(); // std::vector<std::vector<std::pair<K2*, V2*>>> for(const auto& sameKeyPairVector : keyToVectorOfPairs){ shuffledQueue.emplace_back(sameKeyPairVector.second); } } // else => you aren't thread-0, so go wait on barrier }
Let me elaborate my little simple question, can we refactor this function such that this piece of code: std::unordered_map<K2*, IntermediateVec> keyToVectorOfPairs;//IntermediateVec==std::vector<IntermediatePair> for (size_t i = 0; i < currentJobContext_.getNumOfThreads(); ++i){ // std::vector<std::pair<K2*, V2*>> sorted by K2 auto currIntermediateVec = currentJobContext_.getThreadContext(i).getIntermediateVec(); for(const auto& elem : currIntermediateVec){ keyToVectorOfPairs[elem.first].emplace_back(elem); } } Would be inside another method, such that we avoid unnecessary copies?
MSP
I need training and job
Pavel
I need training and job
Good for you, I guess
Shahar
std::atomic<std::uint64_t> jobStateBitwise_; Does someone know how can we manipulate certain bits of such a variable?
Anonymous
std::atomic<std::uint64_t> jobStateBitwise_; Does someone know how can we manipulate certain bits of such a variable?
Use ::load() to get the value, do you bit manipulations and save them into the variable with ::store() ?
Anonymous
Shahar Do you want to write lock-free algorithms?
Shahar
Use ::load() to get the value, do you bit manipulations and save them into the variable with ::store() ?
Suppose I want to change the only first two bits? Or only the next 31 bits? Or get their appropriate decimal value?
Shahar
Shahar Do you want to write lock-free algorithms?
My multithreaded library requires using of atomic variables
Anonymous
Suppose I want to change the only first two bits? Or only the next 31 bits? Or get their appropriate decimal value?
Hmm... you ::load() the content of this variable into a non-atomic variable, do any operation you want. Then ::store() the result into the atomic variable
Shahar
Hmm... you ::load() the content of this variable into a non-atomic variable, do any operation you want. Then ::store() the result into the atomic variable
Can you give me an example? Suppose I want to store at the beginning of this atomic variable the number 3 whose bitwise number is 01, how would you do it? Also, suppose you want to store the number 37 whose bitwise number is some_binary inside certain 31 bits in this atomic variable, how would you do it? The point is, I have to manipulate 64-bit atomic variable in these chunks: 2-bit, 31-bit, 31-bit
Anonymous
"how would you do it?" Hmm... RTFM? :)
Shahar
"how would you do it?" Hmm... RTFM? :)
You have a relevant M? becuase I didn't find anything dealing with this matter
Anonymous
https://riptutorial.com/cplusplus/example/24687/atomic-types
Anonymous
Required me 10 seconds of google search
Anonymous
Recommended reading is: https://en.cppreference.com/w/cpp/atomic/atomic
Anonymous
You have a relevant M? becuase I didn't find anything dealing with this matter
Is your issue dealing with std::atomic or is it bit manipulation?
Anonymous
bit manipulation thing
Hmm.. isn't this one of the first things explained in every programming book?
Shahar
Thanks dude
'''''''
Hey guys, while developing a quiz platform, we r running a timer, and as soon as the user presses 1/2/3/4 the timer must stop and that key must be stored. Can u pls suggest me of a way. I already know of a way, but that would require the user to press a random key to stop the timer and then press the option he chooses I'm doing it in C
Shahar
I have a std::vector<std::vector<std::pair<K, V>>>, and I want to sum up the number of `pair`s inside this vector of vectors of pairs. Is there an elegant way of doing that, or just iterating over each vector, summing its size() up?
Anonymous
I have a std::vector<std::vector<std::pair<K, V>>>, and I want to sum up the number of `pair`s inside this vector of vectors of pairs. Is there an elegant way of doing that, or just iterating over each vector, summing its size() up?
https://en.cppreference.com/w/cpp/algorithm/accumulate Sorry for asking again: Have you tried to google it or... reading a book? Pls don't get me wrong or rude. I'm just wondering, because this questions sounds like home work...
Anonymous
Hi
Anonymous
I need to help
Anonymous
For my c progrmming exam
Anonymous
Can you help me please
Pavel
Is it possible to make a compile error in a constexpr if (in a normal function)? I have a long chain of constexpr if-elseif and I want to have an else clause that will report an error at compile time if it ever can be reached, but I can't find how to do that
Parra
typedef int assert ## __LINE__ [!!(condition) ? 1 : -1];
Parra
it should work with templates, not sure about constexpr, I'm a guy from old standards
Pavel
typedef int assert ## __LINE__ [!!(condition) ? 1 : -1];
Should it be in a macro function definition?
Parra
you can do both
Parra
in a template or a macro, I usually do it in a macro because I use C
Pavel
It fails to compile without macro, trying with it
Pavel
how are you doing it?
#define COMPILE_ERROR(cond) typedef int assert ## __LINE__ [!!(condition) ? 1 : -1]; then in the code constexpr if (something) { } else { COMPILE_ERROR(false); }
Parra
by the way, why reimplementing it? https://en.cppreference.com/w/cpp/language/static_assert
Pavel
I mean I can put a long-long condition from each if case into one assert, but that won't be very good
Parra
wait
Parra
if you are using constexpr you can just throw an exception
Parra
it will halt the compilation
Pavel
if you are using constexpr you can just throw an exception
not sure if I can do that in a non-constexpr function, I think it will result in throwing it at runtime
Parra
so you want the same static_assert to work in constexpr and non-constexpr at the same time?
Pavel
no, let me share some code
Pavel
so you want the same static_assert to work in constexpr and non-constexpr at the same time?
I have a template function like this that decides at compile time which branch will be executed https://pastebin.com/tiVFdhF7 But the branch itself is executed at runtime