Blame test/mpi/rma/accfence2_am.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2003 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include <stdlib.h>
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
Packit 0848f5
#ifndef MAX_INT
Packit 0848f5
#define MAX_INT 0x7fffffff
Packit 0848f5
#endif
Packit 0848f5
Packit 0848f5
/*
Packit 0848f5
static char MTEST_Descrip[] = "Test MPI_Accumulate with fence";
Packit 0848f5
*/
Packit 0848f5
Packit 0848f5
/* same as accfence2.c, but uses alloc_mem */
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    int errs = 0;
Packit 0848f5
    int rank, size, source;
Packit 0848f5
    int minsize = 2, count, i;
Packit 0848f5
    MPI_Comm comm;
Packit 0848f5
    MPI_Win win;
Packit 0848f5
    int *winbuf, *sbuf;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    /* The following illustrates the use of the routines to
Packit 0848f5
     * run through a selection of communicators and datatypes.
Packit 0848f5
     * Use subsets of these for tests that do not involve combinations
Packit 0848f5
     * of communicators, datatypes, and counts of datatypes */
Packit 0848f5
    while (MTestGetIntracommGeneral(&comm, minsize, 1)) {
Packit 0848f5
        if (comm == MPI_COMM_NULL)
Packit 0848f5
            continue;
Packit 0848f5
        /* Determine the sender and receiver */
Packit 0848f5
        MPI_Comm_rank(comm, &rank;;
Packit 0848f5
        MPI_Comm_size(comm, &size);
Packit 0848f5
        source = 0;
Packit 0848f5
Packit 0848f5
        for (count = 32768; count < 65000; count = count * 2) {
Packit 0848f5
Packit 0848f5
            /* We compare with an integer value that can be as large as
Packit 0848f5
             * size * (count * count + (1/2)*(size-1))
Packit 0848f5
             * For large machines (size large), this can exceed the
Packit 0848f5
             * maximum integer for some large values of count.  We check
Packit 0848f5
             * that in advance and break this loop if the above value
Packit 0848f5
             * would exceed MAX_INT.  Specifically,
Packit 0848f5
             *
Packit 0848f5
             * size*count*count + (1/2)*size*(size-1) > MAX_INT
Packit 0848f5
             * count*count > (MAX_INT/size - (1/2)*(size-1))
Packit 0848f5
             */
Packit 0848f5
            if (count * count > (MAX_INT / size - (size - 1) / 2))
Packit 0848f5
                break;
Packit 0848f5
Packit 0848f5
            MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &winbuf);
Packit 0848f5
            MPI_Alloc_mem(count * sizeof(int), MPI_INFO_NULL, &sbuf);
Packit 0848f5
Packit 0848f5
            for (i = 0; i < count; i++)
Packit 0848f5
                winbuf[i] = 0;
Packit 0848f5
            for (i = 0; i < count; i++)
Packit 0848f5
                sbuf[i] = rank + i * count;
Packit 0848f5
            MPI_Win_create(winbuf, count * sizeof(int), sizeof(int), MPI_INFO_NULL, comm, &win);
Packit 0848f5
            MPI_Win_fence(0, win);
Packit 0848f5
            MPI_Accumulate(sbuf, count, MPI_INT, source, 0, count, MPI_INT, MPI_SUM, win);
Packit 0848f5
            MPI_Win_fence(0, win);
Packit 0848f5
            if (rank == source) {
Packit 0848f5
                /* Check the results */
Packit 0848f5
                for (i = 0; i < count; i++) {
Packit 0848f5
                    int result = i * count * size + (size * (size - 1)) / 2;
Packit 0848f5
                    if (winbuf[i] != result) {
Packit 0848f5
                        if (errs < 10) {
Packit 0848f5
                            fprintf(stderr,
Packit 0848f5
                                    "Winbuf[%d] = %d, expected %d (count = %d, size = %d)\n", i,
Packit 0848f5
                                    winbuf[i], result, count, size);
Packit 0848f5
                        }
Packit 0848f5
                        errs++;
Packit 0848f5
                    }
Packit 0848f5
                }
Packit 0848f5
            }
Packit 0848f5
Packit 0848f5
            MPI_Win_free(&win);
Packit 0848f5
Packit 0848f5
            MPI_Free_mem(winbuf);
Packit 0848f5
            MPI_Free_mem(sbuf);
Packit 0848f5
        }
Packit 0848f5
        MTestFreeComm(&comm);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
    return 0;
Packit 0848f5
}