. . Hong Kong Business Software Company
Expert in web-based solutions
Software House in Hong Kong

Microsoft Certified Solution Developer

 

Chief Architect's Blog on software development

5 May 2012

Parallel Task Processing
In a recent project, I was asked to generate a very large and complicated spreadsheet.  The client did not mind to buy a server with powerful multi-core processors.

Multi-core processors can only benifit tasks that can be splitted up. In fact, many tasks need to be worked sequentially and cannot be splitted up for several processors to process them at the same time.   Fortunately, parallel processing is possible in this project because the resulting spreadsheet has many sheets wihich are independent of each others.

Microsoft .Net Framework 4.0 has good support for  parallel task processing.  I first create an array of empty individual sheets and an array of jobs corresponding to each sheet.  All individual sheets together will form a workbook.  I use System.Threading.Tasks.Parallel.For to instruct parallel processing all jobs to create individual sheet to the empty sheet array.   After that I append all sheets to form a workbook.  The code in VB.Net looks like this:



Dim JobCount As Integer = jobList.Length

Dim individualSheet(jobList.Length - 1) As Sheet

System.Threading.Tasks.Parallel.For(0, individualSheet.Length,
                                                 Sub(i)
                                                      individualSheet(i) = DoTask(workSheetTemplate, jobList(i), criteria)
                                                 End Sub
                                                  )

For i As Integer = 0 To jobList.Length - 1
         workBook.Append(individualSheet(i))
Next
Please note that I did not show related classes and functions in the above code because I do not want to complicate the demonstration of parallel processing.


more topics...  

Home | Products | Services | FAQ | Chinese version | Contact Us
© 2008 Bisware Technology Limited. All Rights Reserved.