~ubuntu-branches/ubuntu/vivid/mpich/vivid-proposed

« back to all changes in this revision

Viewing changes to test/mpi/ft/scatter.c

  • Committer: Package Import Robot
  • Author(s): Anton Gladky
  • Date: 2014-04-01 20:24:20 UTC
  • mfrom: (5.2.4 sid)
  • Revision ID: package-import@ubuntu.com-20140401202420-t5ey1ia2klt5dkq3
Tags: 3.1-4
* [c3e3398] Disable test_primitives, which is unreliable on some platforms.
            (Closes: #743047)
* [265a699] Add minimal autotest.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
 
2
/*
 
3
 *
 
4
 *  (C) 2003 by Argonne National Laboratory.
 
5
 *      See COPYRIGHT in top-level directory.
 
6
 */
 
7
#include "mpi.h"
 
8
#include <stdio.h>
 
9
#include <stdlib.h>
 
10
#include <string.h>
 
11
 
 
12
/*
 
13
 * This test attempts collective communication after a process in
 
14
 * the communicator has failed.
 
15
 */
 
16
int main(int argc, char **argv)
 
17
{
 
18
    int rank, size, i, rc, errclass, toterrs, errs = 0;
 
19
    char rbuf[100000];
 
20
    char *sendbuf;
 
21
    int deadprocs[1] = {1};
 
22
    MPI_Group world, newgroup;
 
23
    MPI_Comm newcomm;
 
24
 
 
25
    MPI_Init(&argc, &argv);
 
26
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
27
    MPI_Comm_size(MPI_COMM_WORLD, &size);
 
28
    MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
 
29
 
 
30
    if (size < 3) {
 
31
        fprintf( stderr, "Must run with at least 3 processes\n" );
 
32
        MPI_Abort( MPI_COMM_WORLD, 1 );
 
33
    }
 
34
 
 
35
    if (rank == 1) {
 
36
        exit(EXIT_FAILURE);
 
37
    }
 
38
 
 
39
    /* try a small send first */
 
40
    sendbuf = (char *)malloc(10*size*sizeof(char));
 
41
 
 
42
    if (rank == 0) {
 
43
      for (i=0;i<size;i++) {
 
44
          strcpy(sendbuf + i*10, "No Errors");
 
45
      }
 
46
    }
 
47
 
 
48
    rc = MPI_Scatter(sendbuf, 10, MPI_CHAR, rbuf, 10, MPI_CHAR, 0, MPI_COMM_WORLD);
 
49
 
 
50
#if defined (MPICH) && (MPICH_NUMVERSION >= 30100102)
 
51
    MPI_Error_class(rc, &errclass);
 
52
    if ((rc) && (errclass != MPIX_ERR_PROC_FAIL_STOP)) {
 
53
        fprintf(stderr, "Wrong error code (%d) returned. Expected MPIX_ERR_PROC_FAIL_STOP\n", errclass);
 
54
        errs++;
 
55
    }
 
56
#endif
 
57
 
 
58
    /* reset the buffers and try a larger scatter */
 
59
    free(sendbuf);
 
60
    memset(rbuf, 0, sizeof(rbuf));
 
61
    sendbuf = (char *)malloc(100000*size*sizeof(char));
 
62
 
 
63
    if (rank == 0) {
 
64
      for (i=0;i<size;i++) {
 
65
          strcpy(sendbuf + i*100000, "No Errors");
 
66
      }
 
67
    }
 
68
 
 
69
    rc = MPI_Scatter(sendbuf, 100000, MPI_CHAR, rbuf, 100000, MPI_CHAR, 0, MPI_COMM_WORLD);
 
70
 
 
71
#if defined (MPICH) && (MPICH_NUMVERSION >= 30100102)
 
72
    MPI_Error_class(rc, &errclass);
 
73
    if ((rc) && (errclass != MPIX_ERR_PROC_FAIL_STOP)) {
 
74
        fprintf(stderr, "Wrong error code (%d) returned. Expected MPIX_ERR_PROC_FAIL_STOP\n", errclass);
 
75
        errs++;
 
76
    }
 
77
#endif
 
78
 
 
79
    MPI_Comm_group(MPI_COMM_WORLD, &world);
 
80
    MPI_Group_excl(world, 1, deadprocs, &newgroup);
 
81
    MPI_Comm_create_group(MPI_COMM_WORLD, newgroup, 0, &newcomm);
 
82
 
 
83
    rc = MPI_Reduce(&errs, &toterrs, 1, MPI_INT, MPI_SUM, 0, newcomm);
 
84
    if(rc)
 
85
        fprintf(stderr, "Failed to get errors from other processes\n");
 
86
 
 
87
    if (rank == 0) {
 
88
        if (toterrs) {
 
89
            printf( " Found %d errors\n", toterrs );
 
90
        }
 
91
        else {
 
92
            printf( " No Errors\n" );
 
93
        }
 
94
        fflush(stdout);
 
95
    }
 
96
 
 
97
    free(sendbuf);
 
98
 
 
99
    MPI_Finalize();
 
100
 
 
101
    return 0;
 
102
}