0 Replies - 22144 Views - Last Post: 26 February 2015 - 01:17 PM

#1 Squiva  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 26-February 15

F# parallel programming

Posted 26 February 2015 - 01:17 PM

In this tutorial, I go over how to create a program that runs in parallel in F#. Before I go into anything, I would like to go over what parallel programming is. Parallel programming is the technique where you run multiple threads at once. Next, I would like to go over what F# is. F# is a functional language much like Hascal. A functional language runs things via functions opposed to its partner imperative programming.

Here is my code snippet. In this code snippet, I create a program that runs two functions that run one task, then sleeps, then runs another task. Meanwhile, the other function is running as well doing the same thing.
open System // Imports the System classes
 
let foo = async {  // Define a new Asynchronous program
    printfn "Starting something"; // Prints something
    do! Async.Sleep 100; // Sleeps for a while
    printfn "Finishing something"; // Prints something
}
let bar = async { 
    printfn "Starting something else"
    do! Async.Sleep 100;
    printfn "Finishing something else"
    Console.ReadLine() |> ignore; // Waits for user input
}
 
[foo; bar] // Defines what functions to run asynchronously
|>Async.Parallel // Runs said functions in parallel
|>Async.RunSynchronously // Runs those functions asynchrounously
|>printf "%A" // Stops


Is This A Good Question/Topic? 0
  • +

Page 1 of 1