File: sys2blacs_.c

package info (click to toggle)
scalapack 2.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 37,012 kB
  • sloc: fortran: 339,113; ansic: 74,517; makefile: 1,494; sh: 34
file content (55 lines) | stat: -rw-r--r-- 1,590 bytes parent folder | download | duplicates (2)
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
#include "Bdef.h"

#if (INTFACE == C_CALL)
Int Csys2blacs_handle(MPI_Comm SysCtxt)
#else
Int sys2blacs_handle_(Int *SysCtxt)
#endif
{
#if (INTFACE == C_CALL)
   Int i, j, DEF_WORLD;
   MPI_Comm *tSysCtxt;
   extern Int BI_MaxNSysCtxt;
   extern MPI_Comm *BI_SysContxts;

   if (BI_COMM_WORLD == NULL) 
      Cblacs_pinfo(&i, &j);
   if (SysCtxt == MPI_COMM_NULL)
      BI_BlacsErr(-1, __LINE__, __FILE__,
                  "Cannot define a BLACS system handle based on MPI_COMM_NULL");
/*
 * See if we already have this system handle stored
 */
   for (i=0; i < BI_MaxNSysCtxt; i++)
      if (BI_SysContxts[i] == SysCtxt) return(i);
/*
 * The first time in this routine, we need to define MPI_COMM_WORLD, if it isn't
 * what is already being defined.
 */
   DEF_WORLD = ( (!BI_SysContxts) && (SysCtxt != MPI_COMM_WORLD) );
/*
 * Find free slot in system context array
 */
   for (i=0; i < BI_MaxNSysCtxt; i++)
      if (BI_SysContxts[i] == MPI_COMM_NULL) break;
/*
 * If needed, get a bigger system context array
 */
   if (i == BI_MaxNSysCtxt)
   {
      j = BI_MaxNSysCtxt + MAXNSYSCTXT;
      if ( (MAXNSYSCTXT == 1) && (DEF_WORLD) ) j++;
      tSysCtxt = (MPI_Comm *) malloc(j * sizeof(MPI_Comm));
      for (i=0; i < BI_MaxNSysCtxt; i++) tSysCtxt[i] = BI_SysContxts[i];
      BI_MaxNSysCtxt = j;
      for (j=i; j < BI_MaxNSysCtxt; j++) tSysCtxt[j] = MPI_COMM_NULL;
      if (BI_SysContxts) free(BI_SysContxts);
      BI_SysContxts = tSysCtxt;
   }
   if (DEF_WORLD) BI_SysContxts[i++] = MPI_COMM_WORLD;
   BI_SysContxts[i] = SysCtxt;
   return(i);
#else
   return(*SysCtxt);
#endif
}