[Haskell-cafe] a sort of chunk

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Fri Jan 17 10:10:23 UTC 2020


Hello,

I need to write some code in order to do some computations with stack of images coming from hdf5 files.
Each computation done per images is quite intensive, so I want to do this on multiple cores of my computer (24 in my case)

A stack of images  is composed of  a list of files. each file contain n images.
So I decided to proceed like this: 

create a data type which represent a chunk of this stack.

data Chunk = Chunk { filename :: FilePath
                               , from :: Int
                               , to :: Int
                               }


And indeed the full stack is [Chunk]

Now  since I have n core, I need to split the full stack in equivalent chunk of images.

Just for example. at the begining I have this image stack

30476 images
[Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00077.nxs" 0 698,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00078.nxs" 0 1104,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00079.nxs" 0 1510,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00080.nxs" 0 1914,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00081.nxs" 0 2318,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00082.nxs" 0 2720,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00083.nxs" 0 2169,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00084.nxs" 0 2445,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00085.nxs" 0 2720,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00086.nxs" 0 490,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00087.nxs" 0 812,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00088.nxs" 0 1133,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00089.nxs" 0 1454,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00090.nxs" 0 1773,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00091.nxs" 0 2090,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00092.nxs" 0 2406,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00093.nxs" 0 2720]

so i need to write a function which do something like chunksOf

chunksOf :: Int -> [Chunk] -> [[Chunk]]

In this case I need to create chunk of 1325 images, so the finla result should be

[ [Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00077.nxs" 0 698,Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00078.nxs" 0 627]
, [Chunk "/nfs/ruche-sixs/sixs-soleil/com-sixs/2019/Run3/FeSCO_Cu111/sample2_ascan_omega_00078.nxs" 627 1104, ...]
...
]

I would like your help in order to give me advices or help me find information whcih can help me implement this chunksOf method.

thanks for your help.

Frederic


More information about the Haskell-Cafe mailing list