/dpt/ - Daily Programming Thread

Old thread: What are you working on, Jow Forums?

Attached: 1558319223091.png (929x1300, 1.88M)

Other urls found in this thread:

jsfiddle.net/XBfzn/
youtube.com/watch?v=ojZbFIQSdl8
stackoverflow.com/questions/7083482/how-to-prevent-gcc-from-optimizing-out-a-busy-wait-loop
github.com/electronicarts/EASTL/blob/master/LICENSE
docs.idris-lang.org/en/latest/st/state.html
youtube.com/watch?v=iSmkqocn0oQ
faceb
twitter.com/SFWRedditGifs

I am working on a C++ project, where I need to use multiple processes because of some stupid OS limitations.

I am familiar with multithreading and everything.

What is the best way to do interprocess communication so that it has the highest performance?
My candidates right now are boost::interprocess and OpenMPI.
What are the advantages/disadvantages of each, and how does the speed(it's very important) compare to just using threads?
Also, does anyone know how to set up the development environment to properly recursively launch processes in the cross-platform environment from an initial program without using fork which is not available on Windows? Also, is it possible to have the all be debugged by something like XCode or Visual Studio in parallel? My current best idea for that would be to just launch the second process from Visual Studio and later connect them for Debug.

Any help would be greatly appreciated, even if you just point me in the right direction.

Attached: LearnC++In21Days.jpg (700x600, 100K)

nth for Nim!

It depends a fair bit on your platform. POSIX shared memory is probably the fastest in terms of raw data pumping speeds, but it's a complete bitch to work with and needs external synchronization; I don't know whether windows has an equivalent, but I imagine it does.

Pipes are likely your second best bet, and much more convenient. I know windows has those, but I don't know their details or limitations.

4th for Remi!

Attached: __remilia_scarlet_touhou_drawn_by_60mai__165edab02fdf01e49469404355fb6f28.png (700x722, 542K)

Remilia

Too little information even though you typed a paragraph. Also the image is more interesting than your rant.

Be more specific with what type of program you have, what the threads are doing, and how the communication needs to happen. Also what OS you are using.

How many 1CCs does /dpt/ have? Would you be able to pass the EoSD interview?

I just finished implementing some optimizations one of you fags suggested to me on another thread the other day. Improved quite a bit, so thanks.

Old
>Elapsed time is 3.547076 seconds.
New
>Elapsed time is 0.111263 seconds
On a loop that gets called 14k+ times.

Attached: untitled17.png (915x684, 92K)

I need cross-platform.
If it can't work on at least Windows, Mac and Linux it is pointless.
Preferably something that works even on mobile.

What about virtual files shared memory as is used by boost? Is it slower then pipes?
And what is the speed compared to direct shared memory using threads?

Thanks a lot for the answer!

Ok, the reason why this is necessary in the first place is that I want to open a window without taking over the main thread - and that is IMPOSSIBLE on mac.

So the idea was to launch a second process with the window that handles all the direct rendering stuff and then runs a worker thread on the main process to do dispatched calls.

The basic idea is the following:
Imagine, there was a graphics library in C++ where you can open a window with just one loc, and then draw some stuff with a few commands, and close it. Without building our whole god damned program around it.

PCB, IN, MoF, UFO, TD are my normal 1ccs. Also PCB Extra/Phantasm, IN Extra and TD Extra.

Psst, user!
Don't tell this to anyone... but I think your JavaScript is really cute!

Attached: 3b9f4291794dd3c7f2d3e9fb257e3c1b.jpg (736x1104, 90K)

what algorithm is this exactly? seems interesting

How hard/long was it to beat UFO compared to the rest?

Line of sight for each element.

Attached: untitled18.png (919x695, 62K)

Post joints.

Walls can't see, user.

Definitely the hardest for me, took several times longer than the other 1ccs.

haven't you heard of the phrase "the walls have eyes"?

They can if they have eyes.

Attached: 141.jpg (1200x1680, 575K)

So what am i looking to build here, a daemon?

A program that does nothing except catching commands(or likely jsons) till i activate it to do something with said commands. The problem is can i make something that isn't active/only starts when first called without "opening a window" or hogging some terminal and may as well close itself again after use.

The problem i see here is that when i google daemons i get only results of principles that stay active all the time, which i do wanna avoid. Or is the whole thing pretty simple and i'm overthinking the "how to start"?

Attached: Gtloliqueengtnotaneet_29e3dec39c8f15b179dbc5ca7fcd16b6.jpg (1280x1397, 261K)

How'd you do it in the end?

>What about virtual files shared memory as is used by boost?
I think that's pretty much the same thing as posix shared memory. Or rather, it's a platform-independent abstraction thereof.

>Is it slower then pipes?
Disclaimer: This is my theoretical understanding. I haven't tested any of this.

I think shared memory is faster than pipes in terms of bytes transfered per second, but slower in synchronization. When transferring a small chunk of data over from process A to process B, the synchronization you need to perform to do that safely can easily be slower than the synchronization tricks internally used by the OS primitives that implement across-pipe communication. But throwing twenty megabytes of actual payload data across the boundary is likely considerably faster than doing the same thing over a pipe.

This all means that if you want to transmit an ordered sequence of small chunks of data to the other process, then pipes are probably a much more optimized way of doing that than shared memory. If you are dealing with large bulk data, OR you have complex data flow schemes that do not easily fit the ownership model implied by pipes, shared memory may be the better option. For example, if you have three processes that want to do unpredictable concurrent access of the same chunk of data while synchronizing with mutexes, shared memory is the way to go; but that is pretty rare.

tl;dr: If the type of communication you want to do can easily be done with pipes, and total volume isn't too large, pipes are probably best. If you are dealing with vast amounts of data to be transferred (more than, say, 10 MB/second), consider shared memory.

>And what is the speed compared to direct shared memory using threads?
No fucking clue.

Every process has an input and output stream. Just open the process using a Systemd service, rc.d, service or whatever. Or even call it with nohup and run it in the background iwth & or run it in tmux

There was this function that detected intersections between two segments and run around 3 loops: 1 for each element and 2 for each pair.
function t = inter2(Po, P1, Qo, Q1)
U = P1-Po;
V = Q1-Qo;
Ut = [-U(2); U(1)];
Vt = [-V(2); V(1)];
if(dot(Ut,V)==0)
t = 0;
else
W = Po-Qo;
t1 = (dot(Ut,W)/dot(Ut,V));
t = (t1>0) && (t1

Attached: untitled19.png (958x753, 43K)

Thanks! I'm making a game on it.

remi's armpits

*reimu

gross

What am I doin'? What am I doin'? Oh yeah that's right I'm doin' me, I'm doin' me, and this is what Imma do til it's over, til it's over but it's far from over.

neat! post it when you are done!
jsfiddle.net/XBfzn/

Attached: best_anon.png (822x944, 46K)

I think you're really cute!

wtf why can't you both just like fucking die already

fuck off

no you fuck off
you disgusting pedo scum are not allowed here

pedo website

ive passed pcb normal and im working on eosd normal

how are bjds pedo?

I never finished a 2hu level even on easy.

please don't tell me you're STILL shilling your shitty js challenge?
i don't own any of the games

You can split the wavefunction with sonic tweezers and get random spins on correlated atoms across the galaxy, but only if you use Android Sleepyhead, which is released on the Andromeda Galaxy already.

Don't hope someone will solve your programming assignment, asshole.

I'll look into that.

Attached: 1506797570345.jpg (850x1360, 158K)

Remi is such a lovely girl

You're such a lovely girl

>please don't tell me you're STILL shilling your shitty js challenge?
You are still mad you can't solve it?

It's been fucking days and you're still telling people to do your challenge, do you think you're /dpt/'s college professor or something?

is there a way to make word based NN language models use less memory?
i dont want to strip out 95% of the goddamn vocabulary just to make it fit in memory

CUNNY!

Cute and funny?

gr8 OP

Attached: 1535484406963.png (850x874, 388K)

Chronic shitposters are a cancer killing /dpt/. Literally half the thread is unrelated to programming. If it were just one or two posts it wouldn't be a problem.

Sepples is getting more based by the year. Thanks Haskell!

youtube.com/watch?v=ojZbFIQSdl8

here's another type trick
struct engine_key {};
// important: hide constructor so only initEngine() can see it
std::optional initEngine();
void thingThatRequiresEngineInitialised(engine_key unusedArg);

Nipples!

got bullied by a normie on hackernews, i feel like shit now.

Attached: gfe.jpg (837x736, 36K)

When will C++ get template template parameters that return values?

>posting on hn in any manner
you deserve eternal run-time errors that you can never quite debug completely.

Thanks a lot, user.
I will look which is best for my usecase.

what do you mean

sepples is garbage. Anyone who disagrees with me has a small penis.

Is it even fun to have a career as a codemonkey?

Attached: 9s5y5uc7a1c521.jpg (2172x2172, 1.6M)

template
struct Foo;
We already have
template
struct Bar;
so why not?

No

If you enjoy kissing ass and being someones bitch.

Why do they call me names for using Haskell :(

What names? Simon Peyton Jones?

I would never call you names, Simon Peyton Jones

Can I even get a job if I don't know any statically typed languages?

you can't get a job if you know haskell

int main()
{
while (1);
}
Why doesn't the compiler optimize this loop out?

>wasting cycles cleaning up shit code

In C++, the forward progress guarantee allows the compiler to optimise out loops that do not have observable side effects.
IDK if this is also true in C.

yes, just go do webdev

>massive for loop
>shit tons of calculations
>but they are all ints
>—O3
>compiles to x+1 or something after 5min

>use floats instead
>literally random noise garbage that destroys optimization
floats are cancer fuck jews

>do not have observable side effects
As all good programs should.

I just learned Haskell. Will I get fired now?

Just don't let anybody know.

Because then the program would terminate when it is clearly written to not terminate.
int main() {
for (int i = 0; i < 1000000; i++);
return 0;
}

This program terminates so it is fine to optimize the loop out here.

Not if my intention is to use the loop to stall the program in place of sleep().

stackoverflow.com/questions/7083482/how-to-prevent-gcc-from-optimizing-out-a-busy-wait-loop

Can you simply use EASTL in a commercial product (1-man indie game) for free? github.com/electronicarts/EASTL/blob/master/LICENSE

b-but i'm not a girl

Sorry, C is not designed to guarantee such behaviour and so even using implementation-specific tricks is not future proof when it comes to compiler updates.

It's basically MIT + "don't fucking mention us in your shitty project in any way, nerd".

Except for using volatile, since then whether the program terminates is dependent on the environment, so it cannot be optimized out. But that has its own issues.

>I am familiar with multithreading and everything.
>What is the best way to do interprocess communication so that it has the highest performance?
In a way in which your multi-processness isn't slower than single. Parallel/concurrent programming is just another tool, and you only should use it if the benefits outweigh the drawbacks. pthreads vs mpi vs boost all focus on different things, take a cursory glance and see which is best. I'd probably use pthreads because I'd prefer to do independent stuff in parallel, then set some flag bits at the end and have a thread watcher just check if stuff is finished. Message passing or back-and-forth threading is a different beast with a lot of complexity, but it may be more relevant to your goals. An example, a GPU absolutely has more computation power for numbers than a CPU. An ASIC/FPGA can do some things even faster. Each has their benefits and drawbacks and shouldn't be used in certain applications.

you can make some non-optimizable calculations in loop so it want remove it, like calc sum by prime modulo. you anyway would be wasting process time

If you do a dummy calculation and throw away the result, the compiler is free to optimize it out. It may not be clever enough to do so in all circumstances, but that is not something that you should depend on.

If you are working with a microcontroller and you have to wait for a certain number of cycles, it is highly questionable to be doing so in C instead of assembly in the first place.

MySQL newbie here.

I want to create an EVENT which deletes entries older than 30mins from a table called sessions. This event would run every minute indefinitely.

How do I write this stuff, I couldn't really find a proper example online and the documentation left me with more questions.

Attached: 1555454828349.jpg (1080x1079, 121K)

cron or a systemd timer would do that nicely.

C++. I want to compare 2 input files containing some links in alphabetical order and check whether some of the links in the first file are added/deleted. Of course, I could simply use for loops, but I would like to know what other approaches I could consider. Thanks in advance!

Why do people still use Java when C# and WPF exists?

Why do people use C# when F# exists?

Every program without side effects is equivalent to the empty program, i.e useless.

you can define side-effects but handle them purely. docs.idris-lang.org/en/latest/st/state.html

A program without observable side effects is not useful, according to SPJ: youtube.com/watch?v=iSmkqocn0oQ

F# is gay. I spent 5 minutes with it, didn't understand what was happening and deemed it an obsolete language, so that just makes you an idiot.

How do you have events and GUI without side effects?

You're wrong, according to Math, but sure

newest Carmacks' rant, everyone.

faceb
ook.com/permalink.php?story_fbid=2407256322842204&id=100006735798590

Dude, check out this 100% pure C code:
eval("x = 10");