File: free_blacs_system_handle_.c

package info (click to toggle)
blacs-mpi 1.1-28.2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,320 kB
  • ctags: 2,031
  • sloc: fortran: 14,968; ansic: 12,353; makefile: 531; sh: 1
file content (51 lines) | stat: -rw-r--r-- 1,517 bytes parent folder | download | duplicates (9)
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
#include "Bdef.h"

/* This file from mpiblacs_patch01 */
#if (INTFACE == C_CALL)
void Cfree_blacs_system_handle(int ISysCtxt)
#else
void free_blacs_system_handle_(int *ISysCxt)
#endif
{
#if (INTFACE == C_CALL)
   int i, j, DEF_WORLD;
   BI_MPI_Comm *tSysCtxt;
   extern int BI_MaxNSysCtxt;
   extern BI_MPI_Comm *BI_SysContxts;


   if ( (ISysCtxt < BI_MaxNSysCtxt) && (ISysCtxt > 0) )
   {
      if (BI_SysContxts[ISysCtxt] != BI_MPI_COMM_NULL)
         BI_SysContxts[ISysCtxt] = BI_MPI_COMM_NULL;
      else BI_BlacsWarn(-1, __LINE__, __FILE__,
          "Trying to free non-existent system context handle %d", ISysCtxt);
   }
   else if (ISysCtxt == 0) return;  /* never free MPI_COMM_WORLD */
   else BI_BlacsWarn(-1, __LINE__, __FILE__,
        "Trying to free non-existent system context handle %d", ISysCtxt);

/*
 * See if we have freed enough space to decrease the size of our table
 */
   for (i=j=0; i < BI_MaxNSysCtxt; i++)
      if (BI_SysContxts[i] == BI_MPI_COMM_NULL) j++;
/*
 * If needed, get a smaller system context array
 */
   if (j > 2*MAXNSYSCTXT)
   {
      j = BI_MaxNSysCtxt - MAXNSYSCTXT;
      tSysCtxt = (BI_MPI_Comm *) malloc(j * sizeof(BI_MPI_Comm));
      for (i=j=0; i < BI_MaxNSysCtxt; i++)
      {
         if (BI_SysContxts[i] != BI_MPI_COMM_NULL)
            tSysCtxt[j++] = BI_SysContxts[i];
      }
      BI_MaxNSysCtxt -= MAXNSYSCTXT;
      for(; j < BI_MaxNSysCtxt; j++) tSysCtxt[j] = BI_MPI_COMM_NULL;
      free(BI_SysContxts);
      BI_SysContxts = tSysCtxt;
   }
#endif
}