File: BI_EmergencyBuff.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 (50 lines) | stat: -rw-r--r-- 1,576 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
#include "Bdef.h"

/***************************************************************************
 *  If there is insufficient space to allocate a needed buffer, this       *
 *  routine is called.  It moniters active buffers for the time defined by *
 *  the user-changeable macro value BUFWAIT.  If in that time no active    *
 *  buffer becomes inactive, a hang is assumed, and the grid is killed.    *
 ***************************************************************************/
void BI_EmergencyBuff(Int length)
{
   void BI_UpdateBuffs(BLACBUFF *);

   char *cptr;
   Int i, j;
   double Mwalltime(void);
   double t1;
   extern Int BI_Np;
   extern BLACBUFF *BI_ReadyB, *BI_ActiveQ;

   j = sizeof(BLACBUFF);
   if (j % sizeof(MPI_Request))
      j += sizeof(MPI_Request) - j % sizeof(MPI_Request);
   i = j + BI_Np*sizeof(MPI_Request);
   if (i % BUFFALIGN) i += BUFFALIGN - i % BUFFALIGN;
   t1 =  Mwalltime();
   while ( (BI_ActiveQ) && (Mwalltime() - t1 < BUFWAIT) && !(BI_ReadyB) )
   {
      BI_UpdateBuffs(NULL);
      if (BI_ReadyB)
      {
         if (BI_ReadyB->Len < length)
         {
	    free(BI_ReadyB);
            cptr = malloc(length + i);
            BI_ReadyB = (BLACBUFF *) cptr;
            if (BI_ReadyB)
            {
               BI_ReadyB->nAops = 0;
               BI_ReadyB->Aops = (MPI_Request *) &cptr[j];
               BI_ReadyB->Buff = &cptr[i];
               BI_ReadyB->Len = length;
            }
         }
      }
   }
   if (BI_ReadyB == NULL)
   {
      BI_BlacsErr(-1, __LINE__, __FILE__, "BLACS out of buffer space");
   }
}