Thread: "forall" statement

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    6

    "forall" statement

    Hello,
    I was just reading a book on parallel programming and there are many C code examples on a statement which looks something like this:

    Code:
    forall (i=0; i<=n; i++)
    I googled around for "forall" and it says everywhere that this is actually HPF (High performance FORTRAN) statement for achieveing loop parallelization on multiprocessor systems but I found no information that this can be used in C. However, in the book all examples are shown in C.
    So, are there any C compilers that support "forall" statement? I tried this in GNU gcc 3.x C compiler but it doesn't work. Does GNU gcc 4.x C compiler support this?
    Also, since this looks like a very simple loop paralelization method (you just add "forall" and that's it? - even more simple than OpenMP), is this effective parallelizing loops?

    thanks for any information.

    regards

    c.

  2. #2
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    There is no standard for paralell processing in C or C++, you must use third-party libs (which are often macros).

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    first time for me I see such thing

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Is it like foreach in perl?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    6
    In many parallel programming books and tutorials there are examples of this "forall" construsct but I haven't seen any C compilers capable of doing that. What it does is simply create n separate parallel processes executed at the same time - for example if we have:

    Code:
    forall (i=0; i<=10; i++)
    ..it means that for every single i there is going to be a separate process. This would greately simplify loop parallelization on numerically intensive computations on multiprocessor systems and you wouldn't have to go through all that threads, forks, MPI, OMP, ..you name it.. simply just add "forall" and thatt's it.
    I don't know, that's why I'm asking, the book I have - "Parallel programming (Wilkinson, Allen), Prentice/Hall 1999" uses those "forall" constructs all over the book just as if it was a normal C construct without including any libraries !!!???
    It does say on one page that sometimes C compilers use "parfor" instead "forall". After I googled around I came across this page:

    http://www.cs.nyu.edu/milan/publications/sd97/

    Code:
    par { 
    	parfor (int i=0; i<N; i++) {
    		statment_1; statment_1;
    	 	: : : :
    		statement_n; statement_n;
    	}
    }
    ..hmm, looks like C languege to me, ..and another example from the above link:

    Code:
    #include "chime.h"
    #include <stdlib.h>
    #include <iostream.h>
    const int N=500;
    
    float A[N][N], B[N][N], C[N][N];
    void RandomFill(float mat[N][N], int size){
    	for(int i=0; i<size; i++)
    	for(int j=0; j<size; j++)
    		mat[i][j] = rand();
    } /* RandomFill */
    
    void main(int argc, char *argv[]){
    	int numOfSubDiv;
    	cout << "Input num of sub divisions: ";
    	cin >> numOfSubDiv ;
    	RandomFill(A,N);
    	RandomFill(B,N);
    	parfor(int division=0; division < numOfSubDiv; division++){
    int from = division * (N/numOfSubDiv);
    		int to = from + (N/numOfSubDiv);
    		for(int i=from; i<to; i++)
    		for(int j=0; j<N; j++){
    		C[i][j] = 0;
    		for (int k=0; k<N; k++)
    			C[i][j] += A[i][k] * B[k][j];
    		}
    	} /* parfor */
    } /* main */
    So, "parfor" should be for C ?

    Which compilers? Is this "chime.h" needed for this? "forall" also seems to be standard construct in Fortarn 95, but all free/GNU Fortran compilers available on the web failed to build on my machine so I can't try this "magical" construct..

    c.

  6. #6
    Registered User
    Join Date
    Jul 2005
    Posts
    6
    Code:
    Is it like foreach in perl?
    sorry, I don't know anything about perl languege - I know just Fortran IV, 77, 90, C and a little of C++. What does "foreach" do? From what I understood, "parfor" and "forall" start all loops as separate processes at the same time - sounds simple and VERY useful for clusters etc. that's all..

    c.

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    This type of support is typically built into the compiler itself.

    Google("parallelizing C compiler")

    Happy hunting.

    gg

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by mitakeet
    There is no standard for paralell processing in C or C++, you must use third-party libs (which are often macros).
    Code:
    #define forall for

    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    I typecast anyway.
    Join Date
    Jun 2005
    Posts
    25
    Quote Originally Posted by quzah
    Code:
    #define forall for

    Quzah.
    True, this will make it work, but it's no longer doing anything in parallel.

    Although, I've never heard of a statement that simple setting everything up in parallel. Even MPI, which is pretty easy to use, has a lot more code involved than that. But then again, MPI is the only parallel experience I have so far. Perhaps someone else is familiar with this "forall" approach.

  10. #10
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Parallelizing C compilers have been around for a long time. There's no standard syntax and the actuall means of parallelization varies.

    I've even seen parallelizing pre-processors that turn "forall" statements into actual MPI, PVM, or pthreads code - that a "normal" compiler can then compile.

    gg

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Raptor007
    True, this will make it work, but it's no longer doing anything in parallel.
    Some people have no sense of humor.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. Meaning of this statement?
    By @nthony in forum C Programming
    Replies: 7
    Last Post: 07-16-2006, 02:57 AM
  3. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 02:33 PM
  4. string & if statement
    By Curacao in forum C++ Programming
    Replies: 4
    Last Post: 05-02-2003, 09:56 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM