ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
blacs_map_.c
Go to the documentation of this file.
1 #include "Bdef.h"
2 
3 #if (INTFACE == C_CALL)
4 void Cblacs_gridmap(int *ConTxt, int *usermap, int ldup, int nprow0, int npcol0)
5 #else
6 F_VOID_FUNC blacs_gridmap_(int *ConTxt, int *usermap, int *ldup, int *nprow0,
7  int *npcol0)
8 #endif
9 {
10 
11  MPI_Comm Cblacs2sys_handle(int BlacsCtxt);
12  MPI_Comm BI_TransUserComm(int, int, int *);
13 
14  int info, i, j, Iam, *iptr;
15  int myrow, mycol, nprow, npcol, Ng;
16  BLACSCONTEXT *ctxt, **tCTxts;
17  MPI_Comm comm, tcomm;
18  MPI_Group grp, tgrp;
19 
20  extern BLACSCONTEXT **BI_MyContxts;
21  extern BLACBUFF BI_AuxBuff;
22  extern int BI_Iam, BI_Np, BI_MaxNCtxt;
23  extern MPI_Status *BI_Stats;
24 
25 /*
26  * If first call to blacs_gridmap
27  */
28  if (BI_MaxNCtxt == 0)
29  {
31  BI_AuxBuff.nAops = 0;
32  BI_AuxBuff.Aops = (MPI_Request*)malloc(BI_Np*sizeof(*BI_AuxBuff.Aops));
33  BI_Stats = (MPI_Status *) malloc(BI_Np * sizeof(MPI_Status));
34  }
35 
36  nprow = Mpval(nprow0);
37  npcol = Mpval(npcol0);
38  Ng = nprow * npcol;
39  if ( (Ng > BI_Np) || (nprow < 1) || (npcol < 1) )
40  BI_BlacsErr(-1, -1, "BLACS_GRIDINIT/BLACS_GRIDMAP",
41  "Illegal grid (%d x %d), #procs=%d", nprow, npcol, BI_Np);
42 /*
43  * Form MPI communicator for scope = 'all'
44  */
45  if (Ng > 2) i = Ng;
46  else i = 2;
47  iptr = (int *) malloc(i*sizeof(int));
48  for (j=0; j < npcol; j++)
49  {
50  for (i=0; i < nprow; i++) iptr[i*npcol+j] = usermap[j*Mpval(ldup)+i];
51  }
52 #if (INTFACE == C_CALL)
53  tcomm = Cblacs2sys_handle(*ConTxt);
54  MPI_Comm_group(tcomm, &grp); /* find input comm's group */
55  MPI_Group_incl(grp, Ng, iptr, &tgrp); /* form new group */
56  MPI_Comm_create(tcomm, tgrp, &comm); /* create new comm */
57  MPI_Group_free(&tgrp);
58  MPI_Group_free(&grp);
59 #else /* gridmap called from fortran */
60  comm = BI_TransUserComm(*ConTxt, Ng, iptr);
61 #endif
62 
63 /*
64  * Weed out callers who are not participating in present grid
65  */
66  if (comm == MPI_COMM_NULL)
67  {
68  *ConTxt = NOTINCONTEXT;
69  free(iptr);
70  return;
71  }
72 
73 /*
74  * ==================================================
75  * Get new context and add it to my array of contexts
76  * ==================================================
77  */
78  ctxt = (BLACSCONTEXT *) malloc(sizeof(BLACSCONTEXT));
79 /*
80  * Find free slot in my context array
81  */
82  for (i=0; i < BI_MaxNCtxt; i++) if (BI_MyContxts[i] == NULL) break;
83 /*
84  * Get bigger context pointer array, if needed
85  */
86  if (i == BI_MaxNCtxt)
87  {
88  j = BI_MaxNCtxt + MAXNCTXT;
89  tCTxts = (BLACSCONTEXT **) malloc(j * sizeof(*tCTxts));
90  for (i=0; i < BI_MaxNCtxt; i++) tCTxts[i] = BI_MyContxts[i];
91  BI_MaxNCtxt = j;
92  for(j=i; j < BI_MaxNCtxt; j++) tCTxts[j] = NULL;
93  if (BI_MyContxts) free(BI_MyContxts);
94  BI_MyContxts = tCTxts;
95  }
96  BI_MyContxts[i] = ctxt;
97  *ConTxt = i;
98 
99  ctxt->ascp.comm = comm;
100  MPI_Comm_dup(comm, &ctxt->pscp.comm); /* copy acomm for pcomm */
101  MPI_Comm_rank(comm, &Iam); /* find my rank in new comm */
102  myrow = Iam / npcol;
103  mycol = Iam % npcol;
104 
105 /*
106  * Form MPI communicators for scope = 'row'
107  */
108  MPI_Comm_split(comm, myrow, mycol, &ctxt->rscp.comm);
109 /*
110  * Form MPI communicators for scope = 'Column'
111  */
112  MPI_Comm_split(comm, mycol, myrow, &ctxt->cscp.comm);
113 
114  ctxt->rscp.Np = npcol;
115  ctxt->rscp.Iam = mycol;
116  ctxt->cscp.Np = nprow;
117  ctxt->cscp.Iam = myrow;
118  ctxt->pscp.Np = ctxt->ascp.Np = Ng;
119  ctxt->pscp.Iam = ctxt->ascp.Iam = Iam;
120  ctxt->Nr_bs = ctxt->Nr_co = 1;
121  ctxt->Nb_bs = ctxt->Nb_co = 2;
122  ctxt->TopsRepeat = ctxt->TopsCohrnt = 0;
123 
124 /*
125  * ===========================
126  * Set up the message id stuff
127  * ===========================
128  */
129  Cblacs_get(-1, 1, iptr);
130  ctxt->pscp.MinId = ctxt->rscp.MinId = ctxt->cscp.MinId =
131  ctxt->ascp.MinId = ctxt->pscp.ScpId = ctxt->rscp.ScpId =
132  ctxt->cscp.ScpId = ctxt->ascp.ScpId = iptr[0];
133  ctxt->pscp.MaxId = ctxt->rscp.MaxId = ctxt->cscp.MaxId =
134  ctxt->ascp.MaxId = iptr[1];
135  free(iptr);
136 
137 }
bLaCsCoNtExT::TopsRepeat
int TopsRepeat
Definition: Bdef.h:27
NOTINCONTEXT
#define NOTINCONTEXT
Definition: Bdef.h:78
BI_Iam
int BI_Iam
Definition: BI_GlobalVars.c:7
Cblacs_pinfo
void Cblacs_pinfo()
bLaCsCoNtExT::rscp
BLACSSCOPE rscp
Definition: Bdef.h:25
MAXNCTXT
#define MAXNCTXT
Definition: Bdef.h:79
BI_Stats
MPI_Status * BI_Stats
Definition: BI_GlobalVars.c:14
BI_TransUserComm
MPI_Comm BI_TransUserComm(int Ucomm, int Np, int *pmap)
Definition: BI_TransUserComm.c:3
bLaCsCoNtExT::ascp
BLACSSCOPE ascp
Definition: Bdef.h:25
bLaCsScOpE::MinId
int MinId
Definition: Bdef.h:16
bLaCsCoNtExT::pscp
BLACSSCOPE pscp
Definition: Bdef.h:25
bLaCbUfF
Definition: Bdef.h:54
bLaCsScOpE::MaxId
int MaxId
Definition: Bdef.h:16
bLaCsScOpE::Iam
int Iam
Definition: Bdef.h:17
bLaCsCoNtExT::TopsCohrnt
int TopsCohrnt
Definition: Bdef.h:28
bLaCsCoNtExT::Nb_co
int Nb_co
Definition: Bdef.h:30
bLaCsCoNtExT::Nb_bs
int Nb_bs
Definition: Bdef.h:29
bLaCbUfF::Aops
MPI_Request * Aops
Definition: Bdef.h:59
Mpval
#define Mpval(para)
Definition: Bdef.h:261
bLaCsCoNtExT
Definition: Bdef.h:23
Cblacs_gridmap
void Cblacs_gridmap()
BI_Np
int BI_Np
Definition: BI_GlobalVars.c:7
BI_MaxNCtxt
int BI_MaxNCtxt
Definition: BI_GlobalVars.c:5
Cblacs_get
void Cblacs_get()
bLaCsCoNtExT::Nr_bs
int Nr_bs
Definition: Bdef.h:29
F_VOID_FUNC
#define F_VOID_FUNC
Definition: Bdef.h:232
bLaCbUfF::nAops
int nAops
Definition: Bdef.h:58
bLaCsCoNtExT::cscp
BLACSSCOPE cscp
Definition: Bdef.h:25
Bdef.h
bLaCsScOpE::comm
MPI_Comm comm
Definition: Bdef.h:15
BI_AuxBuff
BLACBUFF BI_AuxBuff
Definition: BI_GlobalVars.c:10
bLaCsScOpE::ScpId
int ScpId
Definition: Bdef.h:16
BI_MyContxts
BLACSCONTEXT ** BI_MyContxts
Definition: BI_GlobalVars.c:11
BI_BlacsErr
void BI_BlacsErr(int ConTxt, int line, char *file, char *form,...)
Definition: BI_BlacsErr.c:3
bLaCsCoNtExT::Nr_co
int Nr_co
Definition: Bdef.h:30
bLaCsScOpE::Np
int Np
Definition: Bdef.h:17
blacs_gridmap_
F_VOID_FUNC blacs_gridmap_(int *ConTxt, int *usermap, int *ldup, int *nprow0, int *npcol0)
Definition: blacs_map_.c:6