[MPICH] Help with a problematic simple MPI application that creates directories

Clements, Brent bclements at SBSPlanet.com
Wed Sep 27 21:05:47 CDT 2006


Ok, the goal of the mpi application is to take 3 arguments.... -a NUMBER
of Directories to create -b the number of files to create in each
directory -c the /basedir to use as the directory creation point.

 

I have written this mpi application and I'm at a point where I'm trying
to debug why the individual slave mpi processes aren't actually
performing the mkdir. 

 

I've attached the source to this email if someone wouldn't mind taking a
peek and seeing what I'm doing wrong. 

 

To compile just type

Mpicc -DDEBUG test4.c -o test4

 

To run the app just do mpirun -np 3 ./test4 -a 3 -c /tmp

 

The arguments don't really do anything yet(but you need them to run the
app), since in the code I have some hard coded values.

 

My problem is the "mkdir" part of the code...it never makes the
directory

 

I'd appreciate anyones help with this!!

 

I have a $25.00 gift certificate to Thinkgeek to anyone that can help me
out and point out my probably stupid mistake.

 

Btw, don't snicker, YES THE CODE IS BAD, I just need something as a
proof of concept for my relearning of MPI and I've been fighting this
thing for the past 2 hours.

 

Thanks,

BC

 

SOURCE CODE BELOW:

 

#include <stdio.h>  /* all IO stuff lives here */

#include <stdlib.h> /* exit lives here */

#include <unistd.h> /* getopt lives here */

#include <errno.h>  /* UNIX error handling lives here */

#include <string.h> /* strcpy lives here */

#include <mpi.h>    /* MPI and MPI-IO live here */

#include <sys/stat.h>

 

#define MASTER_RANK 0

#define TRUE 1

#define FALSE 0

#define BOOLEAN int

 

int main( argc, argv )

    int argc;

    char * argv [];

    {

    /* my variables */

 

    int my_rank, i, numdirs, numfiles, pool_size;

    BOOLEAN i_am_the_master = FALSE, input_error = FALSE;

    char * basedir;

    char * dir_name = NULL;

    char rankdirname[300];

 

    /* getopt variables */

 

    extern char* optarg;

    int c;

 

    /* error handling variables */

 

    extern int errno;

 

    /* ACTION */

 

    MPI_Init(&argc, &argv);

    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    MPI_Comm_size(MPI_COMM_WORLD, &pool_size);

 

    if (my_rank == MASTER_RANK)

        i_am_the_master = TRUE;

 

    if (i_am_the_master)

        {

 

        /* read the command line */

 

        while ((c = getopt(argc, argv, "a:b:c:")) != -1)

            switch( c )

                {

                case 'a':

                    numdirs = atoi(optarg);

                    break;

 

                case 'b':

                    numfiles = atoi(optarg);

                    break;

 

                case 'c':

                    basedir = optarg;

                    break;

 

                case '?':

                    return 1;

 

                default:

                    abort();

                }

 

#ifdef DEBUG

 

        printf("basedirname         = %s\n", basedir);

        printf("number_of_directorys  = %d\n", numdirs);

 

#endif

 

        } /* end of if(i_am_the_master) { <read the command line> } */

 

    /* Transmit the effect of reading the command line to other

       processes. */

 

 

    /* If we managed to get here, data read from the command line

       is probably OK. */

    MPI_Bcast(&basedir, sizeof(basedir), MPI_CHAR, MASTER_RANK,
MPI_COMM_WORLD);

    MPI_Bcast(&numdirs, 1, MPI_INT, MASTER_RANK, MPI_COMM_WORLD);

 

    if (!i_am_the_master)

        {

 

        /* Now every process creates its own directory based upon its
own rank */

 

        /* PROBLEMATIC CODE */

        basedir = "/tmp";

        // Create this processes directory name based upon it's rank

        sprintf(rankdirname, "RANK%d", my_rank);

        // Change to the base dir /tmp

        chdir(basedir);

        // make the directory

        mkdir(rankdirname, S_IRWXU);

        printf("Creating Directory: %s/%s\n", basedir, rankdirname);

        /* PROBLEMATIC CODE */

 

 

        printf("number_of_directorys  = %d\n", numdirs);

 

        printf("MY RANK = %d\n", my_rank);

        }

    else

        {

        printf("MY RANK = %d\n", my_rank);

        }

 

    MPI_Finalize();

    exit(0);

    }




The information contained in this transmission may contain privileged and confidential information. 
It is intended only for the use of the person(s) named above. If you are not the intended  
recipient, you are hereby notified that any review, dissemination, distribution or  
duplication of this communication is strictly prohibited. If you are not the intended recipient, 
please contact the sender by reply email and destroy all copies of the original message. 
To reply to our email administrator directly, please send an email to postmaster at sbsplanet.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20060927/e1f6e382/attachment.htm>


More information about the mpich-discuss mailing list