[Beowulf] Re: A start in Parallel Programming?

Peter St. John peter.st.john at gmail.com
Wed Mar 14 08:43:46 PDT 2007


On 3/13/07, David Mathog <mathog at caltech.edu> wrote:
...

if(i==1){}
> else if(i==2){}
> etc.
>
> Hopefully things have improved since then. It is possible to force a
> sort of computed goto in C (transfer control staying
> within a function) but it involves pre-storing addresses of labels in
> an array and then transferring control via a pointer retrieved
> via an index into that array.  It's too hideous to contemplate,
> ...


It may be too hideous to contemplate, but it's not too hideous to do, if you
want to micromanage efficiency in the proverbial innermost loop. I was just
looking at a friend's code that trades looping for indexing into an array;
it's not real pretty, grubby string munging. (It may be available as a mini
Sourceforge project, soon, but I think it will end up in an existing
package; "memrspn")

 I've just made up a toy example that I've attached.
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.beowulf.org/pipermail/beowulf/attachments/20070314/98d671ca/attachment.html>
-------------- next part --------------
#include <stdio.h>

#define NFUNCS 2

int add1(int n);
int add2(int n);



int main(int argc, char **argv)
{
	//printf("The entry point of \"printf\" is %0x\n", printf);

	char c;

	int (*funcTab[NFUNCS])(int);

	funcTab[0] = (add1);
	funcTab[1] = (add2);

	printf("Would you like to add 1 or 2? (1, 2, q, Q): ");
	c = getchar();
	putchar(getchar());
	if(c < '1' || c > '2')
	{
		printf("Exiting.\n");
		return 0;
	}
	printf("The value of 10 incremented is %d\n", ((funcTab[c-'1'])(10)));

	return 0;

}
int add1(int n)
{
	return n+1;
}
int add2(int n)
{
	return n+2;
}


More information about the Beowulf mailing list