From 6604e8466fdc826ccc67cc9e0cabfc85ea8ea0c5 Mon Sep 17 00:00:00 2001 From: markls Date: Thu, 28 Feb 2008 08:18:17 +0000 Subject: [PATCH] added simple usage message to smpirun and removed nonworking sample programs. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5249 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/smpi/sample/allreduce.c | 29 ---- src/smpi/sample/alltoall.c | 173 ------------------------ src/smpi/sample/matrix.c | 254 ------------------------------------ src/smpi/smpirun.in | 6 + 4 files changed, 6 insertions(+), 456 deletions(-) delete mode 100644 src/smpi/sample/allreduce.c delete mode 100644 src/smpi/sample/alltoall.c delete mode 100644 src/smpi/sample/matrix.c diff --git a/src/smpi/sample/allreduce.c b/src/smpi/sample/allreduce.c deleted file mode 100644 index 1f8cd884b4..0000000000 --- a/src/smpi/sample/allreduce.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include - -int main(int argc, char *argv[]) { - int rank, size; - int i; - int *sendbuf, *recvbuf; - MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - sendbuf = malloc(sizeof(int) * size); - recvbuf = malloc(sizeof(int) * size); - for (i = 0; i < size; i++) { - sendbuf[i] = 0; - recvbuf[i] = 0; - } - sendbuf[rank] = rank + 1; - MPI_Allreduce(sendbuf, recvbuf, size, MPI_INT, MPI_SUM, MPI_COMM_WORLD); - printf("node %d has: ", rank); - for (i = 0; i < size; i++) { - printf("%d ", recvbuf[i]); - } - printf("\n"); - free(sendbuf); - free(recvbuf); - MPI_Finalize(); - return 0; -} diff --git a/src/smpi/sample/alltoall.c b/src/smpi/sample/alltoall.c deleted file mode 100644 index c11a6dd416..0000000000 --- a/src/smpi/sample/alltoall.c +++ /dev/null @@ -1,173 +0,0 @@ -#include "mpi.h" -#include -#include -#include -#include - -#ifndef EXIT_SUCCESS -#define EXIT_SUCCESS 0 -#define EXIT_FAILURE 1 -#endif - -// sandler says, compile with mpicc -v alltoalldemo.c -// run with mpirun -np 3 a.out -m 5 - -int main( int argc, char *argv[] ) -{ - int rank, size; - int chunk = 128; - int i; - int j; // added by sandler - int *sb; - int *rb; - int status, gstatus; - - MPI_Init(&argc,&argv); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); - MPI_Comm_size(MPI_COMM_WORLD,&size); - if (rank==0) { - printf("size: %d\n", size); - } - for ( i=1 ; i < argc ; ++i ) { - if ( argv[i][0] != '-' ) { - // added by sandler - fprintf(stderr, "Unrecognized option %s\n", argv[i]);fflush(stderr); - continue; - } - switch(argv[i][1]) { - case 'm': - chunk = atoi(argv[++i]); - if (rank==0) { - printf("chunk: %d\n", chunk); - } - break; - default: - fprintf(stderr, "Unrecognized argument %s\n", argv[i]);fflush(stderr); - MPI_Abort(MPI_COMM_WORLD,EXIT_FAILURE); - } - } - sb = (int *)malloc(size*chunk*sizeof(int)); - if ( !sb ) { - perror( "can't allocate send buffer" );fflush(stderr); - MPI_Abort(MPI_COMM_WORLD,EXIT_FAILURE); - } - rb = (int *)malloc(size*chunk*sizeof(int)); - if ( !rb ) { - perror( "can't allocate recv buffer");fflush(stderr); - free(sb); - MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); - } - - - /* original deino.net: - for ( i=0 ; i < size*chunk ; ++i ) { - sb[i] = sb[i] = rank + 1; - rb[i] = 0; - } - */ - // written by sandler - - if (rank==0) printf("note in the following:\n" - "if you were to compare the sending buffer and the receiving buffer on the SAME processor, \n" - "you might think that the values were getting wiped out. However, each row IS going somewhere. \n" - "The 0th row of processor 0 goes to the 0th row of processor 0\n" - "The 1st row of processor 0 goes to the 0th row of processor 1. (Go look at rb for processor 1!)\n" - "\n" - "Too bad the values don't come out in a deterministic order. That's life!\n" - "\n" - "Now look at the receiving buffer for processor 0.\n" - "The 0th row is from processor 0 (itself).\n" - "The 1st row on processor 0 is from the 0th row on processor 1. (Go look at the sb of processor 1!)\n" - "\n" - "Apparently this is the intended behavior.\n" - "\n" - "Note that each row is always moved as one chunk, unchangeable.\n" - "\n" - "TODO: draw a diagram\n" - ); - - for (i=0; i -#include -#include -#include - -#define ITERATIONS 10 -#define STEPS 1 -#define STEP_SIZE 0 - -#define USAGE_ERROR 1 -#define MALLOC_ERROR 2 -#define GETTIMEOFDAY_ERROR 3 - -void * checked_malloc(int rank, const char * varname, size_t size) { - void * ptr; - ptr = malloc(size); - if (NULL == ptr) { - printf("node %d could not malloc memory for %s.\n", rank, varname); - MPI_Abort(MPI_COMM_WORLD, MALLOC_ERROR); - exit(MALLOC_ERROR); - } - return ptr; -} - -int main(int argc, char* argv[]) { - - // timing/system variables - int iteration, iterations = ITERATIONS; - int step, steps = STEPS, step_size = STEP_SIZE; - long usecs, total_usecs; - struct timeval *start_time, *stop_time; - char *program; - - // mpi/communications variables - int rank; - int row, col; - MPI_Comm row_comm, col_comm; - - // algorithm variables - int N_start, N, P; - int *A, *A_t, *B, *C, *D, *a, *b, *abuf, *bbuf; - int n, i, j, k, I, J; - - MPI_Init(&argc, &argv); - - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - - if (0 == rank) { - int size; - MPI_Comm_size(MPI_COMM_WORLD, &size); - - program = basename(argv[0]); - - // root node parses cmdline args - /* - if (3 > argc || !isdigit(*argv[1]) || !isdigit(*argv[2])) { - printf("usage:\n%s

[]\n", program); - MPI_Abort(MPI_COMM_WORLD, USAGE_ERROR); - exit(USAGE_ERROR); - } - */ - - //N_start = atoi(argv[1]); - //P = atoi(argv[2]); - N_start = 100; - P = 2; - - /* - if (4 <= argc && isdigit(*argv[3])) { - iterations = atoi(argv[3]); - } - - if (5 <= argc && isdigit(*argv[4])) { - steps = atoi(argv[4]); - } - - if (6 <= argc && isdigit(*argv[5])) { - step_size = atoi(argv[5]); - } - */ - - if (P*P != size) { - printf("P^2 must equal size.\n"); - MPI_Abort(MPI_COMM_WORLD, USAGE_ERROR); - exit(USAGE_ERROR); - } - - start_time = (struct timeval *)checked_malloc(rank, "start_time", sizeof(struct timeval)); - stop_time = (struct timeval *)checked_malloc(rank, "stop_time", sizeof(struct timeval)); - - } - - // send command line parameters except N, since it can vary - MPI_Bcast(&P, 1, MPI_INT, 0, MPI_COMM_WORLD); - MPI_Bcast(&iterations, 1, MPI_INT, 0, MPI_COMM_WORLD); - MPI_Bcast(&steps, 1, MPI_INT, 0, MPI_COMM_WORLD); - MPI_Bcast(&step_size, 1, MPI_INT, 0, MPI_COMM_WORLD); - - row = rank / P; - col = rank % P; - - // create row/column communicators - MPI_Comm_split(MPI_COMM_WORLD, row, col, &row_comm); - MPI_Comm_split(MPI_COMM_WORLD, col, row, &col_comm); - - for (step = 0; step < steps; step++) { - - total_usecs = 0; - - if (0 == rank) { - N = N_start + step * step_size; - if ((N/P)*P != N) { - printf("P must divide N and %d does not divide %d.\n", P, N); - N = -1; - } - } - - MPI_Bcast(&N, 1, MPI_INT, 0, MPI_COMM_WORLD); - - // if root passes N = -1, skip this round - if (-1 == N) continue; - - n = N / P; - - // initialize matrix components - A = (int *)checked_malloc(rank, "A", n*n*sizeof(int)); - A_t = (int *)checked_malloc(rank, "A_t", n*n*sizeof(int)); - B = (int *)checked_malloc(rank, "B", n*n*sizeof(int)); - C = (int *)checked_malloc(rank, "C", n*n*sizeof(int)); - D = (int *)checked_malloc(rank, "D", n*n*sizeof(int)); - - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) { - - I = n*row+i; - J = n*col+j; - - A[n*i+j] = I+J; - B[n*i+j] = I; - - // d is the check matrix - D[n*i+j] = 0; - for (k = 0; k < N; k++) { - // A[I,k] = I+k - // B[k,J] = k - D[n*i+j] += (I+k) * k; - } - - } - } - - // buffers - abuf = (int *)checked_malloc(rank, "abuf", n*sizeof(int)); - bbuf = (int *)checked_malloc(rank, "bbuf", n*sizeof(int)); - - for (iteration = 0; iteration < iterations; iteration++) { - - for (i = 0; i < n*n; i++) { - C[i] = 0; - } - - // node zero sets start time - if (0 == rank && -1 == gettimeofday(start_time, NULL)) { - printf("couldn't set start_time on node 0!\n"); - MPI_Abort(MPI_COMM_WORLD, GETTIMEOFDAY_ERROR); - exit(GETTIMEOFDAY_ERROR); - } - - // populate transpose of A - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) { - A_t[n*i+j] = A[n*j+i]; - } - } - - // perform calculations - for (k = 0; k < N; k++) { - - if (k/n == col) { - a = A_t + n*(k%n); - } else { - a = abuf; - } - - if (k/n == row) { - b = B + n*(k%n); - } else { - b = bbuf; - } - - MPI_Bcast(a, n, MPI_INT, k/n, row_comm); - MPI_Bcast(b, n, MPI_INT, k/n, col_comm); - - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) { - C[n*i+j] += a[i] * b[j]; - } - } - - } // for k - - // node zero sets stop time - if (0 == rank && -1 == gettimeofday(stop_time, NULL)) { - printf("couldn't set stop_time on node 0!\n"); - MPI_Abort(MPI_COMM_WORLD, GETTIMEOFDAY_ERROR); - exit(GETTIMEOFDAY_ERROR); - } - - // check calculation - for (i = 0; i < n*n && C[i] == D[i]; i++); - j = (n*n == i); - MPI_Reduce(&j, &k, 1, MPI_INT, MPI_LAND, 0, MPI_COMM_WORLD); - - // node zero prints stats - if (0 == rank) { - usecs = (stop_time->tv_sec*1000000+stop_time->tv_usec) - (start_time->tv_sec*1000000+start_time->tv_usec); - printf("prog: %s, N: %d, P: %d, procs: %d, time: %d us, check: %d\n", program, N, P, P*P, usecs, k); - total_usecs += usecs; - } - - } - - // node 0 prints final stats - if (0 == rank) { - printf("prog: %s, N: %d, P: %d, procs: %d, iterations: %d, avg. time: %d us\n", - program, N, P, P*P, iterations, total_usecs / iterations); - } - - // free data structures - free(A); - free(A_t); - free(B); - free(C); - free(D); - free(abuf); - free(bbuf); - - } - - if (0 == rank) { - free(start_time); - free(stop_time); - } - - MPI_Finalize(); - - return 0; -} diff --git a/src/smpi/smpirun.in b/src/smpi/smpirun.in index e18b2715d0..5211e87020 100755 --- a/src/smpi/smpirun.in +++ b/src/smpi/smpirun.in @@ -27,6 +27,12 @@ while true; do NETWORK_LATENCY="$2" shift 2 ;; + "-help") + echo "usage:" + echo "$0 [-np ] [-bandwidth ] [-latency ] program [program-options]" + echo + exit + ;; *) break ;; -- 2.20.1