Does F# provide you automatic parallelism?

2019-02-02 08:54发布

By this I meant: when you design your app side effects free, etc, will F# code be automatically distributed across all cores?

8条回答
狗以群分
2楼-- · 2019-02-02 09:09

No it will not. You must still explicitly marshal calls to other threads via one of the many mechanisms supported by F#.

查看更多
ら.Afraid
3楼-- · 2019-02-02 09:12

No, I'm afraid not. Given that F# isn't a pure functional language (in the strictest sense), it would be rather difficult to do so I believe. The primary way to make good use of parallelism in F# is to use Async Workflows (mainly via the Async module I believe). The TPL (Task Parallel Library), which is being introduced with .NET 4.0, is going to fulfil a similar role in F# (though notably it can be used in all .NET languages equally well), though I can't say I'm sure exactly how it's going to integrate with the existing async framework. Perhaps Microsoft will simply advise the use of the TPL for everything, or maybe they will leave both as an option and one will eventually become the de facto standard...

Anyway, here are a few articles on asynchronous programming/workflows in F# to get you started.

查看更多
劫难
4楼-- · 2019-02-02 09:18

No, I'm pretty sure that it won't automatically parallelise for you. It would have to know that your code was side-effect free, which could be hard to prove, for one thing.

Of course, F# can make it easier to parallelise your code, particularly if you don't have any side effects... but that's a different matter.

查看更多
姐就是有狂的资本
5楼-- · 2019-02-02 09:20

Like the others mentioned, F# will not automatically scale across cores and will still require a framework such as the port of ParallelFX that Josh mentioned.

F# is commonly associated with potential for parallel processing because it defaults to objects being immutable, removing the need for locking for many scenarios.

查看更多
男人必须洒脱
6楼-- · 2019-02-02 09:20

My understanding is that it won't but Parallel Extensions is being modified to make it consumable by F#. Which won't make it automatically multi-thread it, should make it very easy to achieve.

查看更多
戒情不戒烟
7楼-- · 2019-02-02 09:22

F# does not make it automatic, it just makes it easy.

Yet another chance to link to Luca's PDC talk. Eight minutes starting at 52:20 are an awesome demo of F# async workflows. It rocks!

查看更多
登录 后发表回答