source: CIVL/examples/mpi/collective/vectorSum_bad.c@ 240d6f3

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 240d6f3 was 240d6f3, checked in by Manchun Zheng <zmanchun@…>, 11 years ago

added a bad example but CIVL doesn't fail it

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@2103 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 * This program should deadlock but it doesn't.
3 * Not all processes are executing the collective
4 * operations in the same order.
5 */
6#include<mpi.h>
7#include<stdlib.h>
8#include<assert.h>
9#include<stdio.h>
10
11#define SIZE 5
12
13int main()
14{
15 int argc;
16 char** argv;
17 int rank;
18 int procs;
19 int* sendBuf;
20 int* rcvBuf;
21 int* sum;
22
23 MPI_Init(&argc,&argv);
24 MPI_Comm_size(MPI_COMM_WORLD, &procs);
25 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
26
27 if (rank == 0) {
28 sendBuf = (int*)malloc(sizeof(int)*procs);
29 sum = (int*)malloc(sizeof(int)*procs);
30 for(int i=0; i < procs; i++){
31 sendBuf[i] = i;
32 sum[i] = 0;
33 }
34 }else{
35 sum = (int*)malloc(sizeof(int));
36 sendBuf = (int*)malloc(sizeof(int));
37 }
38 rcvBuf = (int*)malloc(sizeof(int)*procs);
39
40 MPI_Scatter(sendBuf, 1, MPI_INT, rcvBuf, 1, MPI_INT, 0, MPI_COMM_WORLD);
41
42 *sendBuf = *rcvBuf;
43
44 if(rank % 2)
45 MPI_Allgather(sendBuf, 1, MPI_INT, rcvBuf, 1, MPI_INT, MPI_COMM_WORLD);
46 else
47 MPI_Scatter(sum, 1, MPI_INT, sum, 1, MPI_INT, 0, MPI_COMM_WORLD);
48
49 printf("Vector process %d is: (", rank);
50 for(int i=0; i<procs; i++){
51 printf("%d", rcvBuf[i]);
52 if(i != procs-1)
53 printf(", ");
54 }
55 printf(")\n");
56
57 if(rank%2)
58 MPI_Scatter(sum, 1, MPI_INT, sum, 1, MPI_INT, 0, MPI_COMM_WORLD);
59 else
60 MPI_Allgather(sendBuf, 1, MPI_INT, rcvBuf, 1, MPI_INT, MPI_COMM_WORLD);
61
62 MPI_Reduce(rcvBuf, sum, procs, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
63
64 if(rank == 0){
65 printf("Vector sum is: (");
66 for(int i=0; i<procs; i++){
67 printf("%d", sum[i]);
68 if(i != procs-1)
69 printf(", ");
70 }
71 printf(")\n");
72 }
73
74 free(sendBuf);
75 free(rcvBuf);
76 free(sum);
77 return 0;
78}
Note: See TracBrowser for help on using the repository browser.