ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
sys2blacs_.c
Go to the documentation of this file.
1 #include "Bdef.h"
2 
3 #if (INTFACE == C_CALL)
4 int Csys2blacs_handle(MPI_Comm SysCtxt)
5 #else
6 int sys2blacs_handle_(int *SysCtxt)
7 #endif
8 {
9 #if (INTFACE == C_CALL)
10  int i, j, DEF_WORLD;
11  MPI_Comm *tSysCtxt;
12  extern int BI_MaxNSysCtxt;
13  extern MPI_Comm *BI_SysContxts;
14 
15  if (BI_COMM_WORLD == NULL)
16  Cblacs_pinfo(&i, &j);
17  if (SysCtxt == MPI_COMM_NULL)
18  BI_BlacsErr(-1, __LINE__, __FILE__,
19  "Cannot define a BLACS system handle based on MPI_COMM_NULL");
20 /*
21  * See if we already have this system handle stored
22  */
23  for (i=0; i < BI_MaxNSysCtxt; i++)
24  if (BI_SysContxts[i] == SysCtxt) return(i);
25 /*
26  * The first time in this routine, we need to define MPI_COMM_WORLD, if it isn't
27  * what is already being defined.
28  */
29  DEF_WORLD = ( (!BI_SysContxts) && (SysCtxt != MPI_COMM_WORLD) );
30 /*
31  * Find free slot in system context array
32  */
33  for (i=0; i < BI_MaxNSysCtxt; i++)
34  if (BI_SysContxts[i] == MPI_COMM_NULL) break;
35 /*
36  * If needed, get a bigger system context array
37  */
38  if (i == BI_MaxNSysCtxt)
39  {
41  if ( (MAXNSYSCTXT == 1) && (DEF_WORLD) ) j++;
42  tSysCtxt = (MPI_Comm *) malloc(j * sizeof(MPI_Comm));
43  for (i=0; i < BI_MaxNSysCtxt; i++) tSysCtxt[i] = BI_SysContxts[i];
44  BI_MaxNSysCtxt = j;
45  for (j=i; j < BI_MaxNSysCtxt; j++) tSysCtxt[j] = MPI_COMM_NULL;
46  if (BI_SysContxts) free(BI_SysContxts);
47  BI_SysContxts = tSysCtxt;
48  }
49  if (DEF_WORLD) BI_SysContxts[i++] = MPI_COMM_WORLD;
50  BI_SysContxts[i] = SysCtxt;
51  return(i);
52 #else
53  return(*SysCtxt);
54 #endif
55 }
Cblacs_pinfo
void Cblacs_pinfo()
BI_SysContxts
MPI_Comm * BI_SysContxts
Definition: BI_GlobalVars.c:12
MAXNSYSCTXT
#define MAXNSYSCTXT
Definition: Bdef.h:80
Bdef.h
BI_BlacsErr
void BI_BlacsErr(int ConTxt, int line, char *file, char *form,...)
Definition: BI_BlacsErr.c:3
BI_MaxNSysCtxt
int BI_MaxNSysCtxt
Definition: BI_GlobalVars.c:6
BI_COMM_WORLD
int * BI_COMM_WORLD
Definition: BI_GlobalVars.c:13
sys2blacs_handle_
int sys2blacs_handle_(int *SysCtxt)
Definition: sys2blacs_.c:6