SCALAPACK 2.2.2
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ blacs_gridmap_()

F_VOID_FUNC blacs_gridmap_ ( Int ConTxt,
Int usermap,
Int ldup,
Int nprow0,
Int npcol0 
)

Definition at line 6 of file blacs_map_.c.

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