File: lamcheckpoint.c

package info (click to toggle)
lam 7.1.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 54,668 kB
  • ctags: 17,034
  • sloc: ansic: 156,264; sh: 9,976; cpp: 7,699; makefile: 5,590; perl: 476; fortran: 260; asm: 83
file content (150 lines) | stat: -rw-r--r-- 3,039 bytes parent folder | download | duplicates (4)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * Copyright (c) 2001-2004 The Trustees of Indiana University.  
 *                         All rights reserved.
 * Copyright (c) 1998-2001 University of Notre Dame. 
 *                         All rights reserved.
 * Copyright (c) 1994-1998 The Ohio State University.  
 *                         All rights reserved.
 * 
 * This file is part of the LAM/MPI software package.  For license
 * information, see the LICENSE file in the top level directory of the
 * LAM/MPI source distribution.
 * 
 * $HEADER$
 *
 * $Id: lamcheckpoint.c,v 1.3 2004/03/09 16:56:10 pcharapa Exp $
 * 
 *	Function:	- checkpoints  an MPI job 
 */	


#include <lam_config.h>

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <all_opt.h>
#include <args.h>
#include <lamdebug.h>
#include <etc_misc.h>

#include <lam-ssi.h>
#include <lam-ssi-cr.h>

OPT *ad;
int param_crlam;

static int strtonum(const char *, pid_t *);

/*
 * main
 */
int
main(int argc, char *argv[]) 
{
  char *cr_module;
  char *pid_arg;
  pid_t pid;
  int errno_save; 
  
  ad = ao_init();
  if (ad == 0) {
    perror("mpirun (ao_init)");
    exit(errno);
  }
  
  ao_setopt(ad, "ssi", 0, 2, 0);
  ao_setopt(ad, "pid", 0, 1, 0);
  
  lam_ssi_base_open(ad);
  lam_ssi_base_ao_setup(ad);
  
  if (ao_parse(ad, &argc, argv)) {
    show_help("lamcheckpoint", "usage", NULL);
    lam_ssi_base_close();
    ao_free(ad);
    exit(EUSAGE);
  }

  param_crlam = lam_ssi_base_param_register_string("cr", 
      NULL, NULL, NULL, NULL);
  
  if (!ao_taken(ad, "pid")) {
    show_help("lamcheckpoint", "usage", NULL);
    lam_ssi_base_close();
    ao_free(ad);
    exit(EUSAGE);
  }

  pid_arg = ao_param(ad, "pid", 0, 0);
 
  if (strtonum(pid_arg, &pid) != 0) {
    show_help("lamcheckpoint", "usage", NULL);
    lam_ssi_base_close();
    ao_free(ad);
    exit(EUSAGE);
  } 
  
  lam_ssi_base_ao_process_args(ad);
  
  if (!ao_taken(ad, "ssi")) {
    show_help("lamcheckpoint", "usage", NULL);
    lam_ssi_base_close();
    ao_free(ad);
    exit(1);
  }
  
   /* Open the CRLAM SSI kind for checkpoint/restart support */
  
  cr_module = lam_ssi_base_param_lookup_string(param_crlam);
  
  if (lam_ssi_crlam_base_open(ad, cr_module) != 0) {
    errno_save = errno;
    free(cr_module);
    lam_ssi_base_close();
    ao_free(ad);
    kexit(errno_save);
  }
  
  if (lam_ssi_crlam.lscrla_lamcheckpoint != NULL) {
    lam_ssi_crlam.lscrla_lamcheckpoint(pid); 
  } else {
    free(cr_module);
    lam_ssi_base_close();
    ao_free(ad);
    exit(1);
  }
  
  ao_free(ad);
  free(cr_module);
  lam_ssi_base_close();
  return 0;
}


/*
 *	strtonum
 *
 *	Function:	- convert string to number if possible
 *			- handles decimal/octal/hexadecimal
 *			- uses strtol()
 *	Accepts:	- string
 *			- ptr number (returned value)
 *	Returns:	- 0 or LAMERROR
 */
static int
strtonum(const char *str, pid_t *pnum)
{
	char		*endstr;		/* end of parsed string */

	*pnum = (int) strtol(str, &endstr, 0);

	if (*endstr) {
		errno = EBADASCIINUMB;
		return(LAMERROR);
	}

	return(0);
}