TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Is parallel programming hard, and, if so, what can you do about it? [pdf]

146 pointsby eric_khunabout 2 years ago

13 comments

dragontamerabout 2 years ago
1. Try process level I&#x2F;O, such pipes, sockets, and the like. Have Linux deal with the concurrency problem, not you. (Note: the BASH &amp; background job works in so many cases it ain&#x27;t funny). Also try fork&#x2F;join parallelism models like OpenMP. These are all far easier than dipping down to a lower level.<p>2. Try a mutex<p>3. If that doesn&#x27;t work, try adding a condition variable.<p>4. If that still doesn&#x27;t work, try an atomic in default sequentially consistent mode or equivalent (ex: Java volatile, InterlockedAdd, and the like). Warning: atomics are very subtle. Definitely have a review with an expert if you are here.<p>5. If that still doesn&#x27;t work, consider lock free paradigms. That is, combinations of atomics and memory barriers.<p>6. If that still doesn&#x27;t work, publish a paper on your problem lol.<p>---------<p>#1 is my most important piece of advice. There was a Blender render I was doing, like 2.6 or something old a few years ago. Blenders parallelism wasn&#x27;t too good and only utilized 25% of my computer.<p>So I ran 4 instances of headless Blender. Bam, 100% utilization. Done.<p>Don&#x27;t overthink parallelism. It&#x27;s stupid easy sometimes, as easy as a &amp; on the end of your shell command.
评论 #34862128 未加载
评论 #34865905 未加载
评论 #34867000 未加载
评论 #34862529 未加载
评论 #34864285 未加载
评论 #34864884 未加载
dangabout 2 years ago
Related:<p><i>“Is Parallel Programming Hard, and, If So, What Can You Do About It?” v2 Is Out</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26537298" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26537298</a> - March 2021 (75 comments)<p><i>Is parallel programming hard, and, if so, what can you do about it?</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22030928" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=22030928</a> - Jan 2020 (85 comments)<p><i>Is Parallel Programming Hard, and, If So, What Can You Do About It? [pdf]</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9315152" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9315152</a> - April 2015 (31 comments)<p><i>Is Parallel Programming Hard, And, If So, What Can You Do About It?</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7381877" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7381877</a> - March 2014 (26 comments)<p><i>Is Parallel Programming Hard, And, If So, What Can You Do About It?</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=2784515" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=2784515</a> - July 2011 (39 comments)
didgetmasterabout 2 years ago
Multi-threaded programming has been of particular interest to me for decades (since my early years programming for OS&#x2F;2). Whenever I write code, I look for ways to do things in parallel.<p>My new data management system is highly parallel. I am always finding tasks that take minutes to complete and getting them down to just seconds (when running on multi-core CPUs) by getting multiple threads working together on the same problem.<p>Just yesterday, I found a task that was taking over 12 minutes to finish (inserting 125 million key&#x2F;value pairs into a data store) and was able to get it to do the same task in just 37 seconds (running on my 16 core&#x2F;32 thread CPU) by spinning off multiple threads.
mhsdefabout 2 years ago
Use an actor model language -- by far the sanest way. Message passing is intuitive to human experience.<p>1. Elixir (Erlang)<p>2. Scala&#x2F;Akka<p>3. Pony
评论 #34865570 未加载
评论 #34867374 未加载
评论 #34866126 未加载
评论 #34864740 未加载
评论 #34865007 未加载
userbinatorabout 2 years ago
Section 2.3.3 is definitely worth reading carefully.<p>I&#x27;ve both increased efficiency and removed bugs by rewriting a system that someone thought the only way to make faster was to add more threads, when optimising algorithms and data layout resulted in much more gains.
评论 #34868896 未加载
college_physicsabout 2 years ago
Its interesting that while Moore&#x27;s law saturated many years ago there is still no parallel programming style that hits some sweet spot between productivity and performance for multicore cpus (and thus gets more adopted for mainstream development)<p>Its not clear if this means there is not such &quot;optimum&quot; or simply it is not something anybody cares about<p>people focused a lot on gpus but thats not easy either
评论 #34863254 未加载
评论 #34863033 未加载
评论 #34863283 未加载
评论 #34862993 未加载
评论 #34866199 未加载
评论 #34867680 未加载
bullenabout 2 years ago
I use OS threads + non-blocking IO with concurrent package for shared data in Java. The performance is incredible.<p>If I wanted to get a little more performance per watt I would probably rewrite it in C with arrays of atomic variables.<p>But you need a VM with GC to be able to be productive during the day and sleep at night, so probably not...
评论 #34866719 未加载
patrulekabout 2 years ago
Its isnt hard but you need to change your programming standpoint. To write parallel code you need to think more about data alignment, dependency and flow. Its quite different than typical object&#x2F;behaviour oriented programming.
gavinhowardabout 2 years ago
Funny. I&#x27;ve been reading this for the past six months and just finished today.<p>Life is weird.
评论 #34862287 未加载
评论 #34862196 未加载
threeseedabout 2 years ago
I use ZIO (<a href="http:&#x2F;&#x2F;zio.dev" rel="nofollow">http:&#x2F;&#x2F;zio.dev</a>) for Scala which makes parallel programming trivial.<p>Wraps different styles of asynchronicity e.g. callbacks, futures, fibers into one coherent model. And has excellent resource management so you can be sure that when you are forking a task that it will always clean up after itself.<p>Have yet to see anything that comes close whilst still being practical i.e. you can leverage the very large ecosystem of Java libraries.
binary0x01about 2 years ago
Try using libthread on plan9, no locks.
delta_p_delta_xabout 2 years ago
My solution is to only solve problems that are embarrassingly parallel, like graphics (one pixel = one thread) or physics simulations (one object = one thread), and escape the pain of synchronisation.
jasfiabout 2 years ago
I use channels to send messages between threads in Nim. It works quite well.