Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 819425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:18:25+00:00 2026-05-15T02:18:25+00:00

I’m trying to parallelize the element by element multiplication of two matrices in F#.

  • 0

I’m trying to parallelize the element by element multiplication of two matrices in F#. I can’t quite figure it out thought. I keep trying to create tasks but it never wants to compile. My non-working messy code is the following:

let myBigElemMultiply (m:matrix) (n:matrix) = 
  let AddTwoRows (row:int) (destination:matrix) (source1:matrix) (source2:matrix) =
      for i in 0 .. destination.NumCols
          destination.[row, i] <- source1.[row,i] + source2.[row,i]
      destination
  let result = Matrix.zero(m.NumRows)
  let operations = [ for i in 0 .. m.NumRows -> AddTwoRows i result m n ]
  let parallelTasks = Async.Parallel operations
  Async.RunSynchronously parallelTasks
  result
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:18:26+00:00Added an answer on May 15, 2026 at 2:18 am

    You have made several small mistakes, e.g., you haven’t figured how to do matrix multiplication.

    let myBigElemMultiply (m:matrix) (n:matrix) = 
      let AddTwoRows (row:int) (destination:matrix) (source1:matrix) (source2:matrix) =
          for col=0 to destination.NumCols-1 do
            let mutable sum = 0.0
            for k=0 to m.NumCols-1 do
              sum <- sum + source1.[row,k] * source2.[k,col]
            destination.[row,col] <- sum
    
      let result = Matrix.zero m.NumRows n.NumCols
      let operations = [ for i=0 to m.NumRows-1 do yield async { AddTwoRows i result m n} ]
      let parallelTasks = Async.Parallel operations
      Async.RunSynchronously parallelTasks |> ignore
      result
    

    One thing to notice is that this code would perform very badly because m.[i,j] is an inefficient way to access elements in a matrix. You’d better use a 2D array:

    let myBigElemMultiply2 (m:matrix) (n:matrix) = 
      let AddTwoRows (row:int) (destination:matrix) (source1:matrix) (source2:matrix) =
          let destination = destination.InternalDenseValues
          let source1 = source1.InternalDenseValues
          let source2 = source2.InternalDenseValues
          for col=0 to Array2D.length2 destination - 1 do
            let mutable sum = 0.0
            for k=0 to Array2D.length1 source2 - 1 do
              sum <- sum + source1.[row,k] * source2.[k,col]
            destination.[row,col] <- sum
    
      let result = Matrix.zero m.NumRows n.NumCols
      let operations = [ for i=0 to m.NumRows-1 do yield async { AddTwoRows i result m n} ]
      let parallelTasks = Async.Parallel operations
      Async.RunSynchronously parallelTasks |> ignore
      result
    

    testing:

    let r = new Random()
    let A = Matrix.init 280 10340 (fun i j -> r.NextDouble() )
    let B = A.Transpose
    

    some timing:

    > myBigElemMultiply A B;;
    Real: 00:00:22.111, CPU: 00:00:41.777, GC gen0: 0, gen1: 0, gen2: 0
    val it : unit = ()
    > myBigElemMultiply2 A B;;
    Real: 00:00:08.736, CPU: 00:00:15.303, GC gen0: 0, gen1: 0, gen2: 0
    val it : unit = ()
    > A*B;;
    Real: 00:00:13.635, CPU: 00:00:13.166, GC gen0: 0, gen1: 0, gen2: 0
    val it : unit = ()
    > 
    

    Check here by using ParallelFor, which should have a better performance than async.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.