File: BI_EmergencyBuff.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 (50 lines) | stat: -rw-r--r-- 1,591 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
#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(BI_MPI_Request))
      j += sizeof(BI_MPI_Request) - j % sizeof(BI_MPI_Request);
   i = j + BI_Np*sizeof(BI_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 = (BI_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");
   }
}