psmile_attach.c

Go to the documentation of this file.
00001 /* --------------------------------------------------------------------- */
00002 /* Copyright 2006-2010, NEC Europe Ltd., London, UK. */
00003 /* All rights reserved. Use is subject to OASIS4 license terms. */
00004 /* --------------------------------------------------------------------- */
00005 
00006 #include <stdio.h>
00007 #include <stddef.h>
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #include <time.h>
00011 #include <sys/types.h>
00012 #include <unistd.h>
00013 
00014 #include "PSMILe_f2c.h"
00015 
00016 #define VOLATILE volatile
00017 
00018 /* -----------------------------------------------------------------------
00019 //BOP
00020  
00021 ! !ROUTINE: psmile_attach
00022  
00023   !INTERFACE:
00024 */
00025  
00026 #ifdef ANSI_C
00027 
00028 void psmile_attach (INTEGER *psmile_rank);
00029 
00030 #else
00031 
00032 void psmile_attach (psmile_rank)
00033 
00034 INTEGER *psmile_rank;
00035 
00036 #endif
00037 /*
00038  
00039   !INPUT PARAMETERS:
00040  
00041       Integer, Intent (In)            :: psmile_rank
00042  
00043       Rank of PSMILe process in comm_psmile
00044  
00045  
00046   !RETURN VALUES:
00047   
00048   !DESCRIPTION:
00049  
00050    Subroutine "psmile_attach" gives the user the possibility
00051    to attach a PSMILe process with rank "psmile_rank" if
00052    the environment variable "PSMILE_ATTACH" is set to this rank.
00053 
00054   !FILES USED:
00055 
00056          <stdio.h>
00057          <stddef.h>
00058          <stdlib.h>
00059          <string.h>
00060 
00061          "mpi.h"
00062          "PSMILe_f2c.h"
00063 
00064   !REVISION HISTORY:
00065 
00066     Date      Programmer   Description
00067   ----------  ----------   -----------
00068   29.11.05    H. Ritzdorf  created
00069  
00070 //EOP
00071 
00072  ----------------------------------------------------------------------
00073   $Id: psmile_attach.c 2325 2010-04-21 15:00:07Z valcke $
00074   $Author: valcke $
00075  ---------------------------------------------------------------------- */
00076 
00077 {
00078    char *env = getenv ("PSMILE_ATTACH");
00079    int rank;
00080    
00081    if (env == NULL) return;
00082 
00083    /* Transform character string into int */
00084 
00085    rank = strtol (env, (char **) NULL, 10);
00086 
00087    if (rank == *psmile_rank) {
00088       time_t t_start, t_end;
00089       VOLATILE int attached = 0;
00090 
00091       fprintf (stderr, "[%d] PSMILe_attach: ### Wait for user attach; pid %d\n",
00092                        *psmile_rank, getpid ());
00093       fflush (stderr);
00094       t_start = time(NULL);
00095 
00096       while (attached == 0) {
00097          t_end = time(NULL);
00098 
00099          if (t_end - t_start > 30 || t_end < t_start) {
00100             fprintf (stderr, "[%d] PSMILe_attach: ### Wait aborted since time limit exceeded\n",
00101                              *psmile_rank);
00102             break;
00103          }
00104       }
00105    }
00106 }

Generated on 18 Mar 2011 for Oasis4 by  doxygen 1.6.1