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 6857177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:59:00+00:00 2026-05-27T01:59:00+00:00

As part of a larger problem, I am trying to define an array inside

  • 0

As part of a larger problem, I am trying to define an array inside an array like so:

import Data.Array.Repa
type Arr = Array DIM2 Int

arr = force $ fromList (Z :. 5 :. 5) [1..25] :: Arr

combined :: Arr
combined = arr `deepSeqArray` 
    traverse arr (\_ -> Z :. 4 :. 4 :: DIM2) (\f (Z :. x :. y) -> 
        let reg = force $ extract f (x,y) (2,2)
        in  reg `deepSeqArray` sumAll reg)

extract :: (DIM2 -> Int) -> (Int,Int) -> (Int,Int) -> Arr
extract lookup (x0,y0) (width,height) = fromFunction bounds 
  $ \sh -> offset lookup sh
    where 
    bounds = Z :. width :. height
    offset :: (DIM2 -> Int) -> DIM2 -> Int
    offset f (Z :. x :. y) = f (Z :. x + x0 :. y + y0)

main = print combined

The extract function is using fromFunction and the lookup function provided to it, but it could also use traverse and arr ! ... for the same effect. Despite using force and deepSeqArray everywhere as early as possible, the console is filled with the message here, followed by the correct result:

Data.Array.Repa: Performing nested parallel computation sequentially.
You’ve probably called the ‘force’ function while another instance was
already running. This can happen if the second version was suspended due
to lazy evaluation. Use ‘deepSeqArray’ to ensure each array is fully
evaluated before you ‘force’ the next one.

While I haven’t constructed a version with lists to compare the speeds, in the larger version performance is suffering.

Is this simply a consequence of nested array definitions and thus I should restructure my program for either the inner or outer definition to be lists? Is my extract function horrible and the cause of the problems?

The tips from this question were useful to get this far but I haven’t yet gone crawling through the compiled code.

  • 1 1 Answer
  • 0 Views
  • 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-27T01:59:01+00:00Added an answer on May 27, 2026 at 1:59 am

    It’s because ‘print’ implicitly forces the array as well. The inner ‘force’ and ‘sumAll’ functions invoke parallel computation, but does ‘print’, so you have nested parallelism. That fact that this is so non-obvious is a great sadness in the Repa 2 API.

    Repa 3 addresses these sort of issues by exporting both sequential and parallel versions of ‘force’ and ‘sumAll’ etc. It also adds a tag to the array type to indicate whether the array is delayed or manifest. Repa 3 isn’t finished yet, but you could use the head version on http://code.ouroborus.net/repa. It should be out shorty after GHC 7.4 later this year.

    Here is a Repa 3 version of your example that runs without giving the warning about nested parallelism. Note that ‘force’ is now ‘compute’.

    import Data.Array.Repa
    
    arr :: Array U DIM2 Int
    arr = fromListUnboxed (Z :. 5 :. 5) [1..25]
    
    combined :: Array U DIM2 Int
    combined 
      = computeP $ traverse arr (\_ -> Z :. 4 :. 4 :: DIM2) 
      $ \f (Z :. x :. y) -> sumAllS $ extract f (x,y) (2,2)
    
    extract :: (DIM2 -> Int) -> (Int,Int) -> (Int,Int) -> Array D DIM2 Int
    extract lookup (x0,y0) (width,height) 
      = fromFunction bounds 
      $ \sh -> offset lookup sh
        where 
        bounds = Z :. width :. height
        offset :: (DIM2 -> Int) -> DIM2 -> Int
        offset f (Z :. x :. y) = f (Z :. x + x0 :. y + y0)
    
    main = print combined
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As part of a larger project I'm trying to implement a facility using JOGL
As part of a larger series of operations, I'm trying to take tokenized chunks
It's a part of larger code base, which forces -Werror on gcc. This warning
As part of a larger web-app (using CakePHP), I'm putting together a simple blog
As part of a larger task performed in R run under windows, I would
As a part of a larger application I need to implement an SSL tunnel
I need to configure Tomcat memory settings as part of a larger installation, so
Assuming self-registration is used to install components as part of a larger installer program,
Looking for a solution in bash (will be part of a larger script). Given
I have a small lightweight application that is used as part of a larger

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.