File: mpe_io.c

package info (click to toggle)
mpich 1.1.0-3
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 22,116 kB
  • ctags: 27,349
  • sloc: ansic: 193,435; sh: 11,172; fortran: 6,545; makefile: 5,801; cpp: 5,020; tcl: 3,548; asm: 3,536; csh: 1,079; java: 614; perl: 183; awk: 168; sed: 70; f90: 62
file content (60 lines) | stat: -rw-r--r-- 1,440 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
51
52
53
54
55
56
57
58
59
60
/*
 * This file contains a start on routines to provide some simple I/O functions
 * for MPE
 */

#if defined(HAVE_CONFIG_H) && !defined(MPICHCONF_INC)
/* This includes the definitions found by configure, and can be found in
   the library directory (lib/$ARCH/$COMM) corresponding to this configuration
 */
#define MPICHCONF_INC
#include "mpichconf.h"
#endif

#include "mpi.h"
#include "mpe.h"
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
/* Prototype for dup2 */
#include <unistd.h>
#endif


#ifndef STDOUT
#define STDOUT 1
#endif

/*@ 
  MPE_IO_Stdout_to_file - Re-direct stdout to a file
 
  Parameters:
.  name - Name of file.  If it contains '%d', this value will be replaced with
  the rank of the process in 'MPI_COMM_WORLD'.

.  mode - Mode to open the file in (see the man page for 'open').  A common
  value is '0644' (Read/Write for owner, Read for everyone else).  
  Note that this
  value is `anded` with your current 'umask' value.

  Notes:
  Some systems may complain when standard output ('stdout') is closed.  
@*/
void MPE_IO_Stdout_to_file( name, mode )
char *name;
int  mode;
{
char fname[1024], *p;
int  rank, fd;

if ((p = strchr(name,'%')) && p[1] == 'd') {
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    sprintf( fname, name, rank );
    fd = open( fname, O_WRONLY | O_CREAT, mode );
    }
else {
    fd = open( name, O_WRONLY | O_CREAT, mode );
    }
dup2( fd, STDOUT );
}