The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Loops and OO and Parallelism

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Keith Ray

Posts: 658
Nickname: keithray
Registered: May, 2003

Keith Ray is multi-platform software developer and Team Leader
Loops and OO and Parallelism Posted: Sep 8, 2006 10:19 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by Keith Ray.
Original Post: Loops and OO and Parallelism
Feed Title: MemoRanda
Feed URL: http://homepage.mac.com/1/homepage404ErrorPage.html
Feed Description: Keith Ray's notes to be remembered on agile software development, project management, oo programming, and other topics.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Keith Ray
Latest Posts From MemoRanda

Advertisement

A person in a dream I had this morning said that whenever you have code that has loops operating on lists, your code is not "object-oriented". Now I don't necessarily agree or disagree, but this was the example I thought of (in my dream):

app tells book 'change margins'

In some implementations, the cascade of method calls to implement that might be:

book loops through its chapters, tells each chapter to 'change margins'.

chapter loops through its pages, tells each page to 'change margins'.

But it could be different. What if the chapters share margin objects from the book, and the pages share margin objects from the chapters? If the data is shared, and not duplicated, then we don't need to loop everywhere changing it. (Though we probably still need to loop somewhere to inform all these objects that the data they depend on changed, and they need to re-layout themselves.)

app tells book to 'change margins'

book tells margins to 'change'.

margins tells all of its dependents (pages) to update themselves. (implied loop)

each page tells all of its dependents (chapters) to update themselves. (implied loop)

each chapter tells all of its dependents (the book) to update themselves.

[but what if pages are dependents of chapters? infinite loop? hmm.]

This dream was partly inspired by an article in MacTech magazine that I read, about parallelizing loops in Fortran-90 and C/C++ using some options available in Intel's compilers for MacOS X. With a couple of C pragmas (or the Fortran equivalent), the compiler takes care of splitting loop processing over multiple CPUs -- doing that yourself using Posix threads would take nearly a page of code, or somewhat smaller if you have threading classes to use.

(It also struck me that Fortran-90 is quite a different language than the Fortran I learned in the 1980's.)

Could you parallelize the looping message cascades of this book / margins example? Maybe. The loops that re-lays out each page and chapter needs one or two pieces of information from the previous page: the previous page number (so we can compute current page number = previous page number + 1). But in fact, there may be more pages than before, if the margins are made smaller. Or fewer pages if the margins are made larger. Maybe "page" is a just a flyweight object and we really only have "book" and "chapter" (or "section") where formatting is concerned. But a chapter still needs to know the last page number of the previous chapter, to get its own page numbering right.

Read: Loops and OO and Parallelism

Topic: The Art of Seaside Previous Topic   Next Topic Topic: The joy of legalese

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use