File: test_mpi.c

package info (click to toggle)
openmx 3.7.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 325,856 kB
  • ctags: 3,575
  • sloc: ansic: 152,655; f90: 2,080; python: 876; makefile: 675; sh: 25; perl: 18
file content (111 lines) | stat: -rw-r--r-- 2,145 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <stdio.h>
#include <stdlib.h>  
#include <math.h>
#include <string.h>
#include <time.h>
#include "mpi.h"
#include "openmx_common.h"

#define asize1   10
#define asize2    8
#define asize3    4


int main(int argc, char *argv[]) 
{
  int numprocs,myid,ID,count,tag,i,j,k;
  int numprocs0,myid0;
  int ID0,vsize0;
  double *v0; 
     

  MPI_Status stat;
  MPI_Request request;

  int Pnum[10];

  Pnum[0] = 4;
  Pnum[1] = 8;
  Pnum[2] = 3;
  Pnum[3] = 2;
  Pnum[4] = 7;
  Pnum[5] = 3;
  



  mpi_comm_level1 = MPI_COMM_WORLD; 
  MPI_Init(&argc,&argv);
  MPI_Comm_size(mpi_comm_level1,&numprocs0);
  MPI_Comm_rank(mpi_comm_level1,&myid0);

  printf("numprocs0=%2d myid0=%2d\n",numprocs0,myid0);

  for (k=0; k<6; k++){

    /* make a new group */

    if (Pnum[k]<numprocs0){

       int *new_ranks; 
       MPI_Group  new_group,old_group; 

       new_ranks = (int*)malloc(sizeof(int)*Pnum[k]);
       for (i=0; i<Pnum[k]; i++) {
         new_ranks[i]=i; /* a new group is made of original rank=0:Pnum[k]-1 */
       }

       MPI_Comm_group(MPI_COMM_WORLD, &old_group);

       /* define a new group */
       MPI_Group_incl(old_group,Pnum[k],new_ranks,&new_group);
       MPI_Comm_create(MPI_COMM_WORLD,new_group,&mpi_comm_level1);

       free(new_ranks); /* never forget cleaning! */
    } 

    if (myid0<Pnum[k]){

      MPI_Comm_size(mpi_comm_level1,&numprocs);
      MPI_Comm_rank(mpi_comm_level1,&myid);
      printf("B k=%3d  numprocs=%3d myid=%3d\n",k,numprocs,myid);
    }

    printf("A k=%3d  numprocs=%3d myid=%3d\n",k,numprocs0,myid0);

    /* return original */

    {
    int *new_ranks; 
    MPI_Group  new_group,old_group; 

    new_ranks = (int*)malloc(sizeof(int)*numprocs0);
    for (i=0; i<numprocs0; i++) {
      new_ranks[i]=i; /* a new group is made of original rank=0:Pnum[k]-1 */
    }

    MPI_Comm_group(MPI_COMM_WORLD, &old_group);

    /* define a new group */
    MPI_Group_incl(old_group,numprocs0,new_ranks,&new_group);
    MPI_Comm_create(MPI_COMM_WORLD,new_group,&mpi_comm_level1);

    free(new_ranks); /* never forget cleaning! */

    }

  }

  MPI_Finalize();
  exit(0);



  return 3;


}