5
/* $Header: /tmp/hpctools/ga/tcgmsg/ipcv4.0/pfilecopy.c,v 1.9 2004-05-07 20:45:10 pollack Exp $ */
14
#include "msgtypesc.h"
16
#if defined(ULTRIX) || defined(SGI) || defined(NEXT) || defined(HPUX) || \
17
defined(KSR) || defined(DECOSF)
18
extern void *malloc();
20
extern void *malloc();
25
void tcgi_pfilecopy(type, node0, filename)
29
Process node0 has a file (assumed unopened) named fname.
30
This file will be copied to all other processes which must
31
simultaneously invoke pfilecopy. Since the processes may be
32
using the same directory one probably ought to make sure
33
that each process uses a different name in the call.
37
on node 0 pfilecopy(99, 0, 'argosin')
38
on node 1 pfilecopy(99, 0, 'argosin_001')
39
on node 2 pfilecopy(99, 0, 'argosin_002')
45
long length, nread=32768, len_nread=sizeof(long);
46
long typenr = (*type & 32767) | MSGINT; /* Force user type integer */
47
long typebuf =(*type & 32767) | MSGCHR;
49
if (!(buffer = malloc((unsigned) nread)))
50
Error("pfilecopy: failed to allocate the I/O buffer",nread);
52
if (*node0 == NODEID_()) {
54
/* I have the original file ... open and check its size */
56
if ((file = fopen(filename,"r")) == (FILE *) NULL) {
57
(void) fprintf(stderr,"me=%ld, filename = %s.\n",NODEID_(),filename);
58
Error("pfilecopy: node0 failed to open original file", *node0);
61
/* Quick sanity check on the length */
63
(void) fseek(file, 0L, (int) 2); /* Seek to end of file */
64
length = ftell(file); /* Find the length of file */
65
(void) fseek(file, 0L, (int) 0); /* Seek to beginning of file */
66
if ( (length<0) || (length>1e12) )
67
Error("pfilecopy: the file length is -ve or very big", length);
69
/* Send the file in chunks of nread bytes */
72
nread = fread(buffer, 1, (int) nread, file);
73
BRDCST_(&typenr, (char *) &nread, &len_nread, node0);
76
BRDCST_(&typebuf, buffer, &nread, node0);
83
/* Open the file for the duplicate */
85
if ((file = fopen(filename,"w+")) == (FILE *) NULL) {
86
(void) fprintf(stderr,"me=%ld, filename = %s.\n",NODEID_(),filename);
87
Error("pfilecopy: failed to open duplicate file", *node0);
90
/* Receive data and write to file */
93
BRDCST_(&typenr, (char *) &nread, &len_nread, node0);
96
BRDCST_(&typebuf, buffer, &nread, node0);
98
if (nread != fwrite(buffer, 1, (int) nread, file))
99
Error("pfilecopy: error data to duplicate file", nread);
104
/* Tidy up the stuff we have been using */
111
void PFILECOPY_(type, node0, filename)
115
tcgi_pfilecopy(type, node0, filename);
119
#define bcopy(a, b, n) memcpy((b), (a), (n))
132
/* This crap because FORTRAN has no standard for passing strings */
135
void PFCOPY_(type, node0, arg)
138
struct char_desc *arg;
140
char *fname = arg->string;
144
void PFCOPY_(type, node0, arg)
149
char *fname = _fcdtocp(arg);
150
int len = _fcdlen(arg);
152
#if !defined(ARDENT) && !defined(CRAY)
153
void PFCOPY_(type, node0, fname, len)
161
/* Fortran wrapper around pfilecopy */
166
(void) printf("me=%d, type=%d, node0=%d, fname=%x, fname=%.8s, len=%d\n",
167
NODEID_(), *type, *node0, fname, fname, len);
170
/* Strip trailing blanks off the file name */
172
while ((len > 0) && (fname[len-1] == ' '))
175
Error("pfcopy_: file name length is toast", (long) len);
177
/* Generate a NULL terminated string */
179
filename = malloc( (unsigned) (len+1) );
181
(void) bcopy(fname, filename, len);
182
filename[len] = '\0';
185
Error("PFCOPY_: failed to malloc space for filename", (long) len);
187
/* Now call the C routine to do the work */
189
tcgi_pfilecopy(type, node0, filename);
191
(void) free(filename);