[Beowulf] Stupid MPI programming question

Mark Hahn hahn at physics.mcmaster.ca
Wed Sep 27 21:14:05 PDT 2006

> Ok, here is the code I'm working with....mkdir keeps giving me a -1 failure...can anyone spot what I"m doing wrong?

why not simply look at errno when you receive the error?

> #define TRUE 1
> #define FALSE 0
> #define BOOLEAN int
> int main( argc, argv )
>    int argc;
>    char* argv [];

using K&R-style parameters is extremely bad practice.

>    {
>    int my_rank, i,pool_size;
>    BOOLEAN i_am_the_master   = FALSE;

personally, I find this bad practice, as well.  the two assignments
to i_am_the_master are separated, and don't offer much, if any,
greater support to the reader of the code than just "rank==MASTER".

>        if (!i_am_the_master)
>        {
>         char fullpath[10000];

technically, you should use PATH_MAX for this.

>         sprintf(fullpath,"/tmp/oooo/RANK%d", my_rank);

snprintf is more robust.

>         int mkdir_return;
>         mkdir_return = mkdir(fullpath,0777);
>         printf("mkdir results: %d\n", mkdir_return);

the idiom should be:

if (mkdir(fullpath,077) == -1)
    fprintf(stderr,"mkdir failed: %d",errno);

but do you ensure that /tmp/oooo already exists before you try to make
the rank-specific subdirectory?

More information about the Beowulf mailing list