1 /***********************************************************************
5 The following is a notice of limited availability of the code and
6 Government license and disclaimer which must be included in the
7 prologue of the code and in all source listings of the code.
10 (c) 1977 University of Chicago
12 Permission is hereby granted to use, reproduce, prepare
13 derivative works, and to redistribute to others at no charge. If
14 you distribute a copy or copies of the Software, or you modify a
15 copy or copies of the Software or any portion of it, thus forming
16 a work based on the Software and make and/or distribute copies of
17 such work, you must meet the following conditions:
19 a) If you make a copy of the Software (modified or verbatim)
20 it must include the copyright notice and Government
21 license and disclaimer.
23 b) You must cause the modified Software to carry prominent
24 notices stating that you changed specified portions of
27 This software was authored by:
29 Argonne National Laboratory
30 J. Michalakes: (630) 252-6646; email: michalak@mcs.anl.gov
31 Mathematics and Computer Science Division
32 Argonne National Laboratory, Argonne, IL 60439
34 ARGONNE NATIONAL LABORATORY (ANL), WITH FACILITIES IN THE STATES
35 OF ILLINOIS AND IDAHO, IS OWNED BY THE UNITED STATES GOVERNMENT,
36 AND OPERATED BY THE UNIVERSITY OF CHICAGO UNDER PROVISION OF A
37 CONTRACT WITH THE DEPARTMENT OF ENERGY.
39 GOVERNMENT LICENSE AND DISCLAIMER
41 This computer code material was prepared, in part, as an account
42 of work sponsored by an agency of the United States Government.
43 The Government is granted for itself and others acting on its
44 behalf a paid-up, nonexclusive, irrevocable worldwide license in
45 this data to reproduce, prepare derivative works, distribute
46 copies to the public, perform publicly and display publicly, and
47 to permit others to do so. NEITHER THE UNITED STATES GOVERNMENT
48 NOR ANY AGENCY THEREOF, NOR THE UNIVERSITY OF CHICAGO, NOR ANY OF
49 THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
50 ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
51 COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS,
52 PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD
53 NOT INFRINGE PRIVATELY OWNED RIGHTS.
55 ***************************************************************************/
61 #include <sys/types.h>
62 #include <sys/socket.h>
63 #include <netinet/in.h>
72 static int first_time_through
= 1 ;
75 static char request_buf
[ 2048 ] ;
77 /* hack for IBM/Chameleon, and other machines/api's that aren't
78 completely competant about flushing FORTRAN I/O before shutting
79 down. We'll do that here, each time a shutdown occurs. That
80 entails keeping track of which files were written to, hence
81 this data structure. */
84 static unsigned char unit_written
[NUNITS
] ;
98 for ( i
= 0 ; i
< NUNITS
; i
++ )
99 unit_written
[i
] = '\0' ;
104 mtag
= MSG_MONITOR_REQUEST
;
105 RSL_RECV( request_buf
, msglen
, mtag
) ;
106 rtype
= (int *) request_buf
;
109 case RSL_READ_REQUEST
:
110 handle_read_request( request_buf
) ;
112 case RSL_WRITE_REQUEST
:
113 handle_write_request( request_buf
) ;
115 case RSL_READ_SPECIAL1
:
116 handle_special1( request_buf
) ;
118 case RSL_READ_SPECIAL2
:
119 handle_special2( request_buf
) ;
121 case RSL_SHUTDOWN_REQUEST
:
122 /* last processor causes shutdown */
124 if ( nshutdown
== rsl_nproc
)
128 sprintf(mess
,"rsl_ioserve: monitor received unknown request %d",*rtype
) ;
129 RSL_TEST_ERR(1,mess
) ;
133 for ( i
= 0 ; i
< NUNITS
; i
++ )
135 if ( unit_written
[i
] != '\0' )
138 RSL_FUNIT_CLOSE ( &x
) ;
144 handle_read_request( req
, resp_me
, pbuf_me
)
145 rsl_read_req_t
* req
;
149 int dim
, i
, k
, ig
, jg
, nelem
;
150 int columnelems
, nbytes
, typelen
, len
, cursor
;
152 int msglen
, mtag
, mdest
;
153 int mlen
, nlen
, minelems
, majelems
;
154 rsl_read_resp_t resp
;
155 int psize
[ RSL_MAXPROC
] ; /* size of messages to each processor */
158 rsl_point_t
*domain
;
161 /* efficiency update from JM, 2002/05/24 */
162 int numpts
[RSL_MAXPROC
], maxnumpts
, iii
;
163 int *iptlst
, *jptlst
, *ip1
, *ip2
;
166 /* bug fix from AJB; rbuf needs to be as large as the
167 domain size (with padding out to factor of 3 for nest
168 dimensions) or may generate a seg-fault in bcopies below
169 in loop that runs over the mlen/nlen dimensions
171 /* figure out size of read buffer needed (includes padding) */
172 nelem_alloc
= domain_info
[req
->domain
].len_m
* domain_info
[req
->domain
].len_n
;
173 switch ( req
->iotag
)
175 case IO2D_IJ
: break ;
176 case IO2D_JI
: break ;
177 case IO3D_IJK
: nelem_alloc
*= req
->glen
[2] ; break ;
178 case IO3D_JIK
: nelem_alloc
*= req
->glen
[2] ; break ;
179 case IO3D_KIJ
: nelem_alloc
*= req
->glen
[0] ; break ;
180 case IO3D_IKJ
: nelem_alloc
*= req
->glen
[1] ; break ;
182 /* figure out number of elements to read into read buffer */
184 for ( dim
= 0 ; dim
< req
->ndim
; dim
++ )
186 nelem
*= req
->glen
[dim
] ;
188 typelen
= elemsize( req
->type
) ;
189 nbytes
= nelem_alloc
* typelen
;
191 rbuf
= RSL_MALLOC( char, nbytes
) ;
193 /* call fortran to read a record from the named unit */
197 bcopy( req
->unit_p
, rbuf
, nbytes
) ;
199 copymem( (void *)req
->unit_p
, typelen
, (void *)rbuf
, typelen
, typelen
, nelem_alloc
) ;
207 FORT_REALREAD ( &(req
->unit
), rbuf
, &nelem
) ;
210 FORT_INTREAD ( &(req
->unit
), rbuf
, &nelem
) ;
214 FORT_DOUBLEREAD ( &(req
->unit
), rbuf
, &nelem
) ;
218 FORT_COMPLEXREAD ( &(req
->unit
), rbuf
, &nelem
) ;
221 FORT_CHARACTERREAD ( &(req
->unit
), rbuf
, &nelem
) ;
224 RSL_TEST_WRN(1,"read operation not yet implemented for this data type") ;
227 /* global record is now stored -- ship it out */
228 switch ( req
->iotag
)
232 minelems
= req
->glen
[0] ;
233 majelems
= req
->glen
[1] ;
237 minelems
= req
->glen
[1] ;
238 majelems
= req
->glen
[0] ;
241 columnelems
= req
->glen
[2] ;
242 minelems
= req
->glen
[0] ;
243 majelems
= req
->glen
[1] ;
246 columnelems
= req
->glen
[2] ;
247 minelems
= req
->glen
[1] ;
248 majelems
= req
->glen
[0] ;
251 columnelems
= req
->glen
[0] ;
252 minelems
= req
->glen
[1] ;
253 majelems
= req
->glen
[2] ;
256 columnelems
= req
->glen
[1] ;
257 minelems
= req
->glen
[0] ;
258 majelems
= req
->glen
[2] ;
261 RSL_TEST_ERR(1,"handle_read_request: unknown data tag") ;
263 /* figure out sizes for each processor */
265 for ( i
= 0 ; i
< rsl_nproc_all
; i
++ ) /* 95/02/22 */
270 mlen
= domain_info
[req
->domain
].len_m
;
271 nlen
= domain_info
[req
->domain
].len_n
;
272 domain
= domain_info
[req
->domain
].domain
;
273 for ( jg
= 0 ; jg
< nlen
; jg
++ )
275 for ( ig
= 0 ; ig
< mlen
; ig
++ )
277 P
= domain
[INDEX_2(jg
,ig
,mlen
)].P
; /* 2002/05/24 */
278 psize
[P
] += columnelems
* typelen
; /* 2002/05/24 */
279 if ( P
>= 0 && P
< rsl_nproc_all
) numpts
[P
]++ ; /* 2002/05/24 */
282 maxnumpts
= 0 ; /* 2002/05/24 */
283 for ( i
= 0 ; i
< rsl_nproc_all
; i
++ ) /* 2002/05/24 */
285 if ( maxnumpts
< numpts
[i
] ) maxnumpts
= numpts
[i
] ; /* 2002/05/24 */
288 iptlst
= RSL_MALLOC( int, rsl_nproc_all
* maxnumpts
) ; /* 2002/05/24 */
289 jptlst
= RSL_MALLOC( int, rsl_nproc_all
* maxnumpts
) ; /* 2002/05/24 */
290 for ( i
= 0 ; i
< rsl_nproc_all
; i
++ ) numpts
[i
] = 0 ; /* 2002/05/24 */
291 for ( jg
= 0 ; jg
< nlen
; jg
++ ) /* 2002/05/24 */
293 for ( ig
= 0 ; ig
< mlen
; ig
++ ) /* 2002/05/24 */
295 P
= domain
[INDEX_2(jg
,ig
,mlen
)].P
; /* 2002/05/24 */
296 if ( P
>= 0 && P
< rsl_nproc_all
) /* 2002/05/24 */
298 iptlst
[INDEX_2(P
,numpts
[P
],maxnumpts
)] = ig
; /* 2002/05/24 */
299 jptlst
[INDEX_2(P
,numpts
[P
],maxnumpts
)] = jg
; /* 2002/05/24 */
300 numpts
[P
]++ ; /* 2002/05/24 */
305 for ( P
= 0 ; P
< rsl_nproc_all
; P
++ ) /* 95/02/22 */
309 pbuf
= RSL_MALLOC( char, len
) ;
310 resp
.response_type
= RSL_READ_RESPONSE
;
311 resp
.sequence
= req
->sequence
;
312 resp
.tofollow
= psize
[P
] ;
314 /*bcopy( &resp, &(pbuf[cursor]), sizeof( resp )) ; cursor += sizeof(resp) ; */
316 /* NOTE AND WARNING: this code is quick and dirty and makes the very
317 naive assumption that the data set being read in is point for point
318 with the domain and is dimensioned to be exactly the same size!!!!
319 Only with this assumption can the ig, jg indices into the domain
320 data structure be used in this way as indices into the data. This
321 will work for MM. A more general approach will require modification. */
324 if ( typelen
== sizeof ( int ) ) {
325 for ( iii
= 0 ; iii
< numpts
[P
] ; iii
++ )
327 ig
= iptlst
[INDEX_2(P
,iii
,maxnumpts
)] ;
328 jg
= jptlst
[INDEX_2(P
,iii
,maxnumpts
)] ;
329 RSL_TEST_ERR( cursor
>= len
,
330 "something wrong with read request: check glen, llen arrays in call") ;
331 switch ( req
->iotag
)
334 ip1
= (int *) &(rbuf
[typelen
*(ig
+jg
*req
->glen
[0])]) ;
335 ip2
= (int *) &(pbuf
[cursor
]) ;
340 ip1
= (int *) &(rbuf
[typelen
*(jg
+ig
*req
->glen
[0])]) ;
341 ip2
= (int *) &(pbuf
[cursor
]) ;
347 ip1
= (int *) &(rbuf
[typelen
*(ig
+req
->glen
[0]*(jg
+k
*req
->glen
[1]))]) ;
348 ip2
= (int *) &(pbuf
[cursor
]) ;
349 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ )
352 ip1
+= req
->glen
[0] * req
->glen
[1] ;
355 cursor
+= typelen
*req
->glen
[2] ;
359 ip1
= (int *) &(rbuf
[typelen
*(jg
+req
->glen
[0]*(ig
+k
*req
->glen
[1]))]) ;
360 ip2
= (int *) &(pbuf
[cursor
]) ;
361 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ )
364 ip1
+= req
->glen
[0] * req
->glen
[1] ;
367 cursor
+= typelen
*req
->glen
[2] ;
371 ip1
= (int *) &(rbuf
[typelen
*(k
+req
->glen
[0]*(ig
+jg
*req
->glen
[1]))]) ;
372 ip2
= (int *) &(pbuf
[cursor
]) ;
373 for ( k
= 0 ; k
< req
->glen
[0] ; k
++ )
379 cursor
+= typelen
*req
->glen
[0] ;
383 ip1
= (int *) &(rbuf
[typelen
*(ig
+req
->glen
[0]*(k
+jg
*req
->glen
[1]))]) ;
384 ip2
= (int *) &(pbuf
[cursor
]) ;
385 for ( k
= 0 ; k
< req
->glen
[1] ; k
++ )
388 ip1
+= req
->glen
[0] ;
391 cursor
+= typelen
*req
->glen
[1] ;
395 } else if ( typelen
== sizeof ( double ) ) {
396 for ( iii
= 0 ; iii
< numpts
[P
] ; iii
++ )
398 ig
= iptlst
[INDEX_2(P
,iii
,maxnumpts
)] ;
399 jg
= jptlst
[INDEX_2(P
,iii
,maxnumpts
)] ;
400 RSL_TEST_ERR( cursor
>= len
,
401 "something wrong with read request: check glen, llen arrays in call") ;
402 switch ( req
->iotag
)
405 dp1
= (double *) &(rbuf
[typelen
*(ig
+jg
*req
->glen
[0])]) ;
406 dp2
= (double *) &(pbuf
[cursor
]) ;
411 dp1
= (double *) &(rbuf
[typelen
*(jg
+ig
*req
->glen
[0])]) ;
412 dp2
= (double *) &(pbuf
[cursor
]) ;
418 dp1
= (double *) &(rbuf
[typelen
*(ig
+req
->glen
[0]*(jg
+k
*req
->glen
[1]))]) ;
419 dp2
= (double *) &(pbuf
[cursor
]) ;
420 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ )
423 dp1
+= req
->glen
[0] * req
->glen
[1] ;
426 cursor
+= typelen
*req
->glen
[2] ;
430 dp1
= (double *) &(rbuf
[typelen
*(jg
+req
->glen
[0]*(ig
+k
*req
->glen
[1]))]) ;
431 dp2
= (double *) &(pbuf
[cursor
]) ;
432 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ )
435 dp1
+= req
->glen
[0] * req
->glen
[1] ;
438 cursor
+= typelen
*req
->glen
[2] ;
442 dp1
= (double *) &(rbuf
[typelen
*(k
+req
->glen
[0]*(ig
+jg
*req
->glen
[1]))]) ;
443 dp2
= (double *) &(pbuf
[cursor
]) ;
444 for ( k
= 0 ; k
< req
->glen
[0] ; k
++ )
450 cursor
+= typelen
*req
->glen
[0] ;
454 dp1
= (double *) &(rbuf
[typelen
*(ig
+req
->glen
[0]*(k
+jg
*req
->glen
[1]))]) ;
455 dp2
= (double *) &(pbuf
[cursor
]) ;
456 for ( k
= 0 ; k
< req
->glen
[1] ; k
++ )
459 dp1
+= req
->glen
[0] ;
462 cursor
+= typelen
*req
->glen
[1] ;
467 for ( iii
= 0 ; iii
< numpts
[P
] ; iii
++ )
469 ig
= iptlst
[INDEX_2(P
,iii
,maxnumpts
)] ;
470 jg
= jptlst
[INDEX_2(P
,iii
,maxnumpts
)] ;
471 RSL_TEST_ERR( cursor
>= len
,
472 "something wrong with read request: check glen, llen arrays in call") ;
473 switch ( req
->iotag
)
476 bcopy(&(rbuf
[typelen
*(ig
+jg
*req
->glen
[0])]),
482 bcopy(&(rbuf
[typelen
*(jg
+ig
*req
->glen
[0])]),
488 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ )
490 bcopy(&(rbuf
[typelen
*(ig
+req
->glen
[0]*(jg
+k
*req
->glen
[1]))]),
497 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ )
499 bcopy(&(rbuf
[typelen
*(jg
+req
->glen
[0]*(ig
+k
*req
->glen
[1]))]),
506 for ( k
= 0 ; k
< req
->glen
[0] ; k
++ )
508 bcopy(&(rbuf
[typelen
*(k
+req
->glen
[0]*(ig
+jg
*req
->glen
[1]))]),
515 for ( k
= 0 ; k
< req
->glen
[1] ; k
++ )
517 bcopy(&(rbuf
[typelen
*(ig
+req
->glen
[0]*(k
+jg
*req
->glen
[1]))]),
527 for ( jg
= 0 ; jg
< nlen
; jg
++ )
529 if ( domain
[INDEX_2(jg
,0,mlen
)].P
== P
)
531 switch ( req
->iotag
)
534 if ( req
->type
== RSL_REAL
)
537 VRCOPY (&(rbuf
[typelen
*(ig
+jg
*req
->glen
[0])]),
540 cursor
+= typelen
*mlen
;
544 for ( ig
= 0 ; ig
< mlen
; ig
++ )
546 bcopy(&(rbuf
[typelen
*(ig
+jg
*req
->glen
[0])]),
554 if ( req
->type
== RSL_REAL
)
556 for ( ig
= 0 ; ig
< mlen
; ig
++ )
558 bcopy(&(rbuf
[typelen
*(jg
+ig
*req
->glen
[0])]),
566 if ( req
->type
== RSL_REAL
)
569 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ )
571 VRCOPY (&(rbuf
[typelen
*(ig
+req
->glen
[0]*(jg
+k
*req
->glen
[1]))]),
574 cursor
+= typelen
*mlen
;
579 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ )
581 for ( ig
= 0 ; ig
< mlen
; ig
++ )
583 bcopy(&(rbuf
[typelen
*(ig
+req
->glen
[0]*(jg
+k
*req
->glen
[1]))]),
592 for ( ig
= 0 ; ig
< mlen
; ig
++ )
594 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ )
596 bcopy(&(rbuf
[typelen
*(jg
+req
->glen
[0]*(ig
+k
*req
->glen
[1]))]),
604 for ( ig
= 0 ; ig
< mlen
; ig
++ )
606 for ( k
= 0 ; k
< req
->glen
[0] ; k
++ )
608 bcopy(&(rbuf
[typelen
*(k
+req
->glen
[0]*(ig
+jg
*req
->glen
[1]))]),
616 for ( ig
= 0 ; ig
< mlen
; ig
++ )
618 for ( k
= 0 ; k
< req
->glen
[1] ; k
++ )
620 bcopy(&(rbuf
[typelen
*(ig
+req
->glen
[0]*(k
+jg
*req
->glen
[1]))]),
632 mdest
= rsl_c_comp2phys_proc( P
) ;
633 mtag
= MTYPE_FROMTO( MSG_READ_RESPONSE
, rsl_myproc
, mdest
) ;
634 msglen
= sizeof( resp
) ;
638 for ( i
= 0 ; i
< msglen
; i
++ )
647 if ( rsl_myproc
== mdest
)
649 bcopy( &resp
, resp_me
, msglen
) ;
654 RSL_SEND( &resp
, msglen
, mtag
, mdest
) ;
655 msglen
= resp
.tofollow
;
656 RSL_SEND( pbuf
, msglen
, mtag
, mdest
) ;
661 RSL_FREE (iptlst
) ; /* 20020524 */
662 RSL_FREE (jptlst
) ; /* 20020524 */
667 static int wrt_sock_err
= 0 ;
669 static int pndomains_init
= 0;
670 static int pndomains
[ RSL_MAXPROC
] ; /* Number of domains for each processor */
674 handle_write_request( req
, nelem
, psize_me
, pbuf_me
)
675 rsl_write_req_t
* req
;
680 int dim
, i
, k
, ig
, jg
, nbytes
;
681 int columnelems
, typelen
, len
, cursor
;
683 int minelems
, majelems
;
684 int msglen
, mtag
, mtag2
, mdest
, mfrom
;
686 rsl_read_resp_t resp
;
687 int psize
[ RSL_MAXPROC
] ; /* size of messages to each processor */
691 rsl_point_t
*domain
;
692 int is_write
, ie_write
, js_write
, je_write
;
699 typelen
= elemsize( req
->type
) ;
700 nbytes
= typelen
* nelem
;
701 wbuf
= RSL_MALLOC( char, nbytes
) ;
703 mlen
= domain_info
[req
->domain
].len_m
;
704 nlen
= domain_info
[req
->domain
].len_n
;
705 domain
= domain_info
[req
->domain
].domain
;
707 /* global record is now stored -- ship it out */
708 switch ( req
->iotag
)
712 case IO2D_IJ_PORTAL
:
715 minelems
= req
->glen
[0] ;
716 majelems
= req
->glen
[1] ;
720 case IO2D_JI_PORTAL
:
723 minelems
= req
->glen
[1] ;
724 majelems
= req
->glen
[0] ;
728 case IO3D_IJK_PORTAL
:
730 columnelems
= req
->glen
[2] ;
731 minelems
= req
->glen
[0] ;
732 majelems
= req
->glen
[1] ;
736 case IO3D_JIK_PORTAL
:
738 columnelems
= req
->glen
[2] ;
739 minelems
= req
->glen
[1] ;
740 majelems
= req
->glen
[0] ;
743 columnelems
= req
->glen
[0] ;
744 minelems
= req
->glen
[1] ;
745 majelems
= req
->glen
[2] ;
748 columnelems
= req
->glen
[1] ;
749 minelems
= req
->glen
[0] ;
750 majelems
= req
->glen
[2] ;
753 RSL_TEST_ERR(1,"handle_write_request: unknown data tag") ;
756 RSL_TEST_ERR( majelems
<= 0, "Major dim spec on write is zero or less.") ;
757 RSL_TEST_ERR( minelems
<= 0, "Minor dim spec on write is zero or less.") ;
758 if ( majelems
> nlen
)
759 { sprintf(mess
,"Major dim spec on write (%d) greater than global domain defini tion in that dimension (%d)\n",majelems
,nlen
) ;
760 RSL_TEST_ERR(1,mess
) ; }
761 if ( minelems
> mlen
)
762 { sprintf(mess
,"Minor dim spec on write (%d) greater than global domain defini tion in that dimension (%d)\n",minelems
,mlen
) ;
763 RSL_TEST_ERR(1,mess
) ; }
765 #if !(defined(NEC_TUNE)) || !(defined(NEC_SINGLENEST))
767 /* figure out sizes for each processor */
769 for ( i
= 0 ; i
< rsl_nproc_all
; i
++ ) /* 95/02/22 */
771 psize
[i
] = (regular_decomp
)?(4*sizeof(int)):0 ;
773 for ( jg
= 0 ; jg
< majelems
; jg
++ )
775 for ( ig
= 0 ; ig
< minelems
; ig
++ )
777 psize
[domain
[INDEX_2(jg
,ig
,mlen
)].P
] += columnelems
* typelen
;
784 Count the number of domains allocated to each processor.
786 for ( i
= 0 ; i
< rsl_nproc_all
; i
++ )
790 for ( i
= 0 ; i
< rsl_nproc_all
; i
++ )
793 for ( jg
= 0 ; jg
< majelems
; jg
++ )
795 for ( ig
= 0 ; ig
< minelems
; ig
++ )
797 if( domain
[INDEX_2(jg
,ig
,mlen
)].P
== i
)
805 for ( i
= 0 ; i
< rsl_nproc_all
; i
++ )
807 psize
[i
] = ((regular_decomp
)?(4*sizeof(int)):0) + pndomains
[i
]*columnelems
*typelen
;
810 #else /* !(defined(NEC_TUNE)) || !(defined(NEC_SINGLENEST)) */
812 if ( ! pndomains_init
)
816 Count the number of domains allocated to each processor.
818 for ( i
= 0 ; i
< rsl_nproc_all
; i
++ )
822 for ( i
= 0 ; i
< rsl_nproc_all
; i
++ )
825 for ( jg
= 0 ; jg
< majelems
; jg
++ )
827 for ( ig
= 0 ; ig
< minelems
; ig
++ )
829 if( domain
[INDEX_2(jg
,ig
,mlen
)].P
== i
)
838 for ( i
= 0 ; i
< rsl_nproc_all
; i
++ )
840 psize
[i
] = ((regular_decomp
)?(4*sizeof(int)):0) + pndomains
[i
]*columnelems
*typelen
;
842 #endif /* !(defined(NEC_TUNE)) || !(defined(NEC_SINGLENEST)) */
844 for ( P
= 0 ; P
< rsl_nproc_all
; P
++ ) /* 95/02/22 */
847 mdest
= rsl_c_comp2phys_proc( P
) ;
848 if ( rsl_myproc
!= mdest
)
851 /* send a short "go ahead" message */
854 mtag2
= MTYPE_FROMTO( MSG_WRITE_COMPUTE_RESPONSE
, rsl_myproc
, mfrom
) ;
855 RSL_SEND( " ", msglen
, mtag2
, mfrom
) ;
858 pbuf
= RSL_MALLOC( char, msglen
) ;
860 mtag2
= MTYPE_FROMTO( MSG_WRITE_COMPUTE_RESPONSE
, mfrom
, rsl_myproc
) ;
861 RSL_RECV( pbuf
, msglen
, mtag2
) ;
865 sprintf(mess
,"psize_me (%d) != psize[P] (%d)", psize_me
,psize
[P
]) ;
866 RSL_TEST_ERR( psize_me
!= psize
[P
], mess
) ;
871 if ( regular_decomp
)
874 bcopy( &(pbuf
[cursor
]), &is_write
, sizeof(int) ) ; cursor
+= sizeof(int) ;
875 bcopy( &(pbuf
[cursor
]), &ie_write
, sizeof(int) ) ; cursor
+= sizeof(int) ;
876 bcopy( &(pbuf
[cursor
]), &js_write
, sizeof(int) ) ; cursor
+= sizeof(int) ;
877 bcopy( &(pbuf
[cursor
]), &je_write
, sizeof(int) ) ; cursor
+= sizeof(int) ;
879 in_write
= ie_write
- is_write
+ 1 ;
881 for ( jg
= js_write
; jg
<= je_write
; jg
++ )
883 switch ( req
->iotag
)
887 case IO2D_IJ_PORTAL
:
889 if ( req
->type
== RSL_REAL
)
892 VRCOPY ( &(pbuf
[cursor
]),
893 &(wbuf
[typelen
*(ig
+jg
*req
->glen
[0])]),
895 cursor
+= in_write
*typelen
;
899 for ( ig
= is_write
; ig
<= ie_write
; ig
++ )
901 bcopy(&(pbuf
[cursor
]),
902 &(wbuf
[typelen
*(ig
+jg
*req
->glen
[0])]),
910 case IO2D_JI_PORTAL
:
912 for ( ig
= is_write
; ig
<= ie_write
; ig
++ )
914 bcopy(&(pbuf
[cursor
]),
915 &(wbuf
[typelen
*(jg
+ig
*req
->glen
[0])]),
922 case IO3D_IJK_PORTAL
:
924 if ( req
->type
== RSL_REAL
)
927 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ ) /* note reversal of i and k on vpp */
929 VRCOPY ( &(pbuf
[cursor
]),
930 &(wbuf
[typelen
*(ig
+req
->glen
[0]*(jg
+k
*req
->glen
[1]))]),
932 cursor
+= typelen
*in_write
;
937 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ ) /* note reversal of i and k on vpp */
939 for ( ig
= is_write
; ig
<= ie_write
; ig
++ )
941 bcopy(&(pbuf
[cursor
]),
942 &(wbuf
[typelen
*(ig
+req
->glen
[0]*(jg
+k
*req
->glen
[1]))]),
951 case IO3D_JIK_PORTAL
:
953 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ )
955 for ( ig
= is_write
; ig
<= ie_write
; ig
++ )
957 bcopy(&(pbuf
[cursor
]),
958 &(wbuf
[typelen
*(jg
+req
->glen
[0]*(ig
+k
*req
->glen
[1]))]),
965 for ( ig
= is_write
; ig
<= ie_write
; ig
++ )
967 for ( k
= 0 ; k
< req
->glen
[0] ; k
++ )
969 bcopy(&(pbuf
[cursor
]),
970 &(wbuf
[typelen
*(k
+req
->glen
[0]*(ig
+jg
*req
->glen
[1]))]),
978 for ( ig
= is_write
; ig
<= ie_write
; ig
++ )
980 for ( k
= 0 ; k
< req
->glen
[1] ; k
++ )
982 bcopy(&(pbuf
[cursor
]),
983 &(wbuf
[typelen
*(ig
+req
->glen
[0]*(k
+jg
*req
->glen
[1]))]),
989 for ( k
= 0 ; k
< req
->glen
[1] ; k
++ )
991 tcursor
= cursor
+ (k
* typelen
) ;
992 copymem(&(pbuf
[tcursor
]), typelen
*req
->glen
[1],
993 &(wbuf
[typelen
*(is_write
+req
->glen
[0]*(k
+jg
*req
->glen
[1]))]), typelen
,
994 typelen
, ie_write
-is_write
+1) ;
996 cursor
+= (ie_write
-is_write
+1)*req
->glen
[1]*typelen
;
1004 for ( jg
= 0 ; jg
< majelems
; jg
++ )
1006 for ( ig
= 0 ; ig
< minelems
; ig
++ )
1008 if ( domain
[INDEX_2(jg
,ig
,mlen
)].P
== P
)
1010 switch ( req
->iotag
)
1014 case IO2D_IJ_PORTAL
:
1016 bcopy(&(pbuf
[cursor
]),
1017 &(wbuf
[typelen
*(ig
+jg
*req
->glen
[0])]),
1023 case IO2D_JI_PORTAL
:
1025 bcopy(&(pbuf
[cursor
]),
1026 &(wbuf
[typelen
*(jg
+ig
*req
->glen
[0])]),
1032 case IO3D_IJK_PORTAL
:
1034 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ )
1036 bcopy(&(pbuf
[cursor
]),
1037 &(wbuf
[typelen
*(ig
+req
->glen
[0]*(jg
+k
*req
->glen
[1]))]),
1044 case IO3D_JIK_PORTAL
:
1046 for ( k
= 0 ; k
< req
->glen
[2] ; k
++ )
1048 bcopy(&(pbuf
[cursor
]),
1049 &(wbuf
[typelen
*(jg
+req
->glen
[0]*(ig
+k
*req
->glen
[1]))]),
1055 for ( k
= 0 ; k
< req
->glen
[0] ; k
++ )
1057 bcopy(&(pbuf
[cursor
]),
1058 &(wbuf
[typelen
*(k
+req
->glen
[0]*(ig
+jg
*req
->glen
[1]))]),
1064 for ( k
= 0 ; k
< req
->glen
[1] ; k
++ )
1066 bcopy(&(pbuf
[cursor
]),
1067 &(wbuf
[typelen
*(ig
+req
->glen
[0]*(k
+jg
*req
->glen
[1]))]),
1078 if ( rsl_myproc
!= rsl_c_comp2phys_proc( P
) )
1080 RSL_FREE( pbuf
) ; /* the monitor frees its own buffer outside
1085 /* mark the unit as needing to be flushed */
1086 if ( ! req
->internal
)
1088 unit_written
[ req
->unit
- 1 ] = (unsigned char) 1 ;
1091 /* start 981228 AFWA_IO */
1092 /* need some kind of graceful failure if the node runs out of memory */
1093 if ( rsl_buffer_output
&& ! req
->internal
)
1095 if ( write_buffer_head
== NULL
&& write_buffer_tail
== NULL
)
1097 write_buffer_head
= RSL_MALLOC( rsl_write_buffer_struct_t
, 1 ) ;
1098 write_buffer_tail
= write_buffer_head
;
1102 write_buffer_tail
->next
= RSL_MALLOC( rsl_write_buffer_struct_t
, 1 ) ;
1103 write_buffer_tail
= write_buffer_tail
->next
;
1105 write_buffer_tail
->req
= *req
;
1106 write_buffer_tail
->nelem
= nelem
;
1107 write_buffer_tail
->buf
= RSL_MALLOC( char, nelem
* elemsize( req
->type
) ) ;
1108 bcopy( wbuf
, write_buffer_tail
->buf
, nelem
* elemsize( req
->type
) ) ;
1112 send_to_output_device( req
, wbuf
, nelem
) ;
1119 /* these routines added for MM5 v3 */
1122 RSL_WRITE_1D_DATA( unit_p
,
1127 char * buf
; int_p nbuf_p
;
1130 rsl_write_req_t req
;
1137 RSL_C_IAMMONITOR( &i_am_monitor
) ;
1138 if ( ! i_am_monitor
) return ;
1142 typelen
= elemsize( type
) ;
1145 req
.request_type
= RSL_WRITE_REQUEST
;
1146 req
.request_mode
= MSG_IO_FORTRAN
;
1147 req
.unit
= *unit_p
;
1148 req
.unit_p
= unit_p
;
1149 req
.iotag
= IO_REPL
;
1152 wbuf
= RSL_MALLOC( char, nelem
*typelen
) ;
1155 bcopy( buf
, wbuf
, nelem
*typelen
) ;
1157 if ( rsl_buffer_output
&& ! req
.internal
)
1159 if ( write_buffer_head
== NULL
&& write_buffer_tail
== NULL
)
1161 write_buffer_head
= RSL_MALLOC( rsl_write_buffer_struct_t
, 1 ) ;
1162 write_buffer_tail
= write_buffer_head
;
1166 write_buffer_tail
->next
= RSL_MALLOC( rsl_write_buffer_struct_t
, 1 ) ;
1167 write_buffer_tail
= write_buffer_tail
->next
;
1169 write_buffer_tail
->req
= req
;
1170 write_buffer_tail
->nelem
= nelem
;
1171 write_buffer_tail
->buf
= RSL_MALLOC( char, nelem
*typelen
) ;
1172 bcopy( wbuf
, write_buffer_tail
->buf
, nelem
*typelen
) ;
1176 send_to_output_device( &req
, wbuf
, nelem
) ;
1182 send_to_output_device( req
, wbuf
, nelem
)
1183 rsl_write_req_t
* req
;
1188 int nbytes
, typelen
, minelems
, majelems
, columnelems
;
1191 typelen
= elemsize( req
->type
) ;
1192 nbytes
= typelen
* nelem
;
1194 /* global record is now stored -- ship it out */
1195 switch ( req
->iotag
)
1199 case IO2D_IJ_PORTAL
:
1202 minelems
= req
->glen
[0] ;
1203 majelems
= req
->glen
[1] ;
1207 case IO2D_JI_PORTAL
:
1210 minelems
= req
->glen
[1] ;
1211 majelems
= req
->glen
[0] ;
1215 case IO3D_IJK_PORTAL
:
1217 columnelems
= req
->glen
[2] ;
1218 minelems
= req
->glen
[0] ;
1219 majelems
= req
->glen
[1] ;
1223 case IO3D_JIK_PORTAL
:
1225 columnelems
= req
->glen
[2] ;
1226 minelems
= req
->glen
[1] ;
1227 majelems
= req
->glen
[0] ;
1230 columnelems
= req
->glen
[0] ;
1231 minelems
= req
->glen
[1] ;
1232 majelems
= req
->glen
[2] ;
1235 columnelems
= req
->glen
[1] ;
1236 minelems
= req
->glen
[0] ;
1237 majelems
= req
->glen
[2] ;
1242 RSL_TEST_ERR(1,"handle_write_request: unknown data tag") ;
1245 if ( req
->request_mode
== MSG_IO_FORTRAN
)
1248 /* call fortran to write a record to the named unit */
1249 if ( req
->internal
)
1251 bcopy( wbuf
, req
->unit_p
, nbytes
) ;
1255 /* call fortran to write a record to the named unit */
1256 switch ( req
->type
)
1259 FORT_REALWRITE ( &(req
->unit
), wbuf
, &nelem
) ;
1262 FORT_INTWRITE ( &(req
->unit
), wbuf
, &nelem
) ;
1266 FORT_DOUBLEWRITE ( &(req
->unit
), wbuf
, &nelem
) ;
1270 FORT_COMPLEXWRITE ( &(req
->unit
), wbuf
, &nelem
) ;
1272 case RSL_CHARACTER
:
1274 FORT_CHARACTERWRITE ( &(req
->unit
), wbuf
, &nelem
) ;
1278 x
= _cptofcd( wbuf
, nelem
) ;
1279 FORT_CHARACTERWRITE ( &(req
->unit
), x
, &nelem
) ;
1284 RSL_TEST_WRN(1,"write operation not implemented for this data type") ;
1289 if ( req
->request_mode
== MSG_IO_SOCKET
)
1291 /* nbytes contains the number of bytes to be written,
1292 wbuf is the buffer to be written,
1293 req->unit is the socket id */
1298 int typelen
, xdim
, ydim
, zdim
;
1301 if ( req
->request_mode2
== MSG_MODE2_RAW
)
1303 if ( write_sock( req
->unit
, wbuf
, nbytes
) < 0 )
1305 perror("writing on socket");
1306 RSL_TEST_WRN(1,"") ;
1310 if ( req
->request_mode2
== MSG_MODE2_FORTRAN
)
1312 /* simulate control words at beginning and end */
1315 if (write_sock(req
->unit
, &cw
, 4) < 0)
1317 perror("writing first control word on socket");
1318 RSL_TEST_WRN(1,"") ;
1320 if (write_sock(req
->unit
, wbuf
, nbytes
) < 0)
1322 perror("writing wbuf on socket");
1323 RSL_TEST_WRN(1,"") ;
1325 if (write_sock(req
->unit
, &cw
, 4) < 0)
1327 perror("writing second control word on socket");
1328 RSL_TEST_WRN(1,"") ;
1332 if ( req
->request_mode2
== MSG_MODE2_PORTAL
)
1334 wbuf_header
.typelen
= typelen
;
1335 wbuf_header
.xdim
= minelems
;
1336 wbuf_header
.ydim
= majelems
;
1337 wbuf_header
.zdim
= columnelems
;
1338 if (write_sock(req
->unit
, &wbuf_header
, sizeof( wbuf_header
) ) < 0)
1340 perror("writing wbuf header on socket");
1341 RSL_TEST_WRN(1,"") ;
1343 if (write_sock(req
->unit
, wbuf
, nbytes
) < 0)
1345 perror("writing wbuf header on socket");
1346 RSL_TEST_WRN(1,"") ;
1350 if ( req
->request_mode2
== MSG_MODE2_88
)
1354 for ( z
= 0; z
< columnelems
; z
++ )
1356 sprintf(outline
,"%d %d\n",majelems
,minelems
) ;
1357 if (write_sock(req
->unit
, outline
, strlen( outline
) ) < 0)
1359 if ( ! wrt_sock_err
)
1362 perror("writing wbuf header on socket");
1363 RSL_TEST_WRN(1,"") ;
1368 for ( ig
= 0 ; ig
< minelems
; ig
++ )
1370 for ( jg
= 0 ; jg
< majelems
; jg
++ )
1372 if ( req
->type
== RSL_REAL
)
1375 bcopy(&(wbuf
[typelen
*(jg
+ig
*req
->glen
[0])]),&a
,sizeof(float)) ;
1376 sprintf(outline
,"%g\n",a
) ;
1378 else if ( req
->type
== RSL_DOUBLE
)
1381 bcopy(&(wbuf
[typelen
*(jg
+ig
*req
->glen
[0])]),&a
,sizeof(double)) ;
1382 sprintf(outline
,"%g\n",a
) ;
1384 else if ( req
->type
== RSL_INTEGER
)
1387 bcopy(&(wbuf
[typelen
*(jg
+ig
*req
->glen
[0])]),&a
,sizeof(int)) ;
1388 sprintf(outline
,"%d\n",a
) ;
1390 if (write_sock(req
->unit
, outline
, strlen(outline
) ) < 0)
1392 if ( ! wrt_sock_err
)
1395 perror("writing wbuf header on socket");
1396 RSL_TEST_WRN(1,"") ;
1406 sprintf(mess
, "Unknown request request_mode2: %d\n",
1407 req
->request_mode2
) ;
1408 RSL_TEST_ERR(1,mess
) ;
1413 sprintf(mess
, "Unknown request request_mode: %d\n",
1414 req
->request_mode
) ;
1415 RSL_TEST_ERR(1,mess
) ;
1419 RSL_OUTPUT_BUFFER_WRITE ()
1422 rsl_write_buffer_struct_t
* p
, * old
;
1423 RSL_C_IAMMONITOR( &i_am_monitor
) ;
1425 if ( rsl_buffer_output
&& i_am_monitor
&& write_buffer_head
!= NULL
)
1427 for ( p
= write_buffer_head
; p
; )
1429 send_to_output_device( &(p
->req
), p
->buf
, p
->nelem
) ;
1430 RSL_FREE( p
->buf
) ;
1436 write_buffer_head
= NULL
;
1437 write_buffer_tail
= NULL
;
1440 RSL_OUTPUT_BUFFER_YES ()
1442 rsl_buffer_output
= 1 ;
1444 RSL_OUTPUT_BUFFER_NO ()
1446 rsl_buffer_output
= 0 ;
1462 write_sock( sd
, buf
, n
)
1467 static int errseen
= 0 ;
1468 int todo
, n_written
;
1471 signal( SIGPIPE
, SIG_IGN
) ; /* if the receiver dies, we should cont */
1476 if ((n_written
= write(sd
, p
, todo
)) < 0 )
1479 perror("write_sock") ;
1480 return( n_written
) ;
1484 } while ( todo
> 0 ) ;
1485 signal( SIGPIPE
, SIG_DFL
) ;
1490 /* On vpp from here to remainder of file, we may be bcopying character strings
1491 so undefine the substution to the vector bcopy */
1492 #if defined(vpp) || defined(vpp2)
1497 RSL_WRITE_MM5V3_SM_HEADER( unit_p
,ndim_p
,
1498 s1_p
,s2_p
,s3_p
,s4_p
,
1499 e1_p
,e2_p
,e3_p
,e4_p
,
1503 staggering_p
, nstaggering_p
,
1504 ordering_p
, nordering_p
,
1505 current_date_p
, ncurrent_date_p
,
1508 description_p
, ndescription_p
)
1511 int_p s1_p
, s2_p
, s3_p
, s4_p
;
1512 int_p e1_p
, e2_p
, e3_p
, e4_p
;
1517 char * staggering_p
; int_p nstaggering_p
;
1518 char * ordering_p
; int_p nordering_p
;
1519 char * current_date_p
; int_p ncurrent_date_p
;
1520 char * name_p
; int_p nname_p
;
1521 char * units_p
; int_p nunits_p
;
1522 char * description_p
; int_p ndescription_p
;
1524 _fcd staggering_p
; int_p nstaggering_p
;
1525 _fcd ordering_p
; int_p nordering_p
;
1526 _fcd current_date_p
; int_p ncurrent_date_p
;
1527 _fcd name_p
; int_p nname_p
;
1528 _fcd units_p
; int_p nunits_p
;
1529 _fcd description_p
; int_p ndescription_p
;
1532 rsl_write_req_t req
;
1541 RSL_C_IAMMONITOR( &i_am_monitor
) ;
1542 if ( ! i_am_monitor
) return ;
1544 iwordsize
= *iwordsize_p
;
1545 rwordsize
= *rwordsize_p
;
1546 nstringbytes
= *nstaggering_p
+ *nordering_p
+ *ncurrent_date_p
1547 + *nname_p
+ *nunits_p
+ *ndescription_p
;
1549 nelem
= 9 * iwordsize
+ 1 * rwordsize
+ nstringbytes
;
1551 nelem
= 9 * iwordsize
/2 + 1 * rwordsize
/2 + nstringbytes
;
1555 req
.request_type
= RSL_WRITE_REQUEST
;
1556 req
.request_mode
= MSG_IO_FORTRAN
;
1557 req
.unit
= *unit_p
;
1558 req
.unit_p
= unit_p
;
1559 req
.iotag
= IO_REPL
;
1560 req
.type
= RSL_CHARACTER
;
1562 wbuf
= RSL_MALLOC( char, nelem
) ;
1566 bcopy( ndim_p
, &(wbuf
[icurs
]), iwordsize
) ; icurs
+= iwordsize
;
1567 bcopy( s1_p
, &(wbuf
[icurs
]), iwordsize
) ; icurs
+= iwordsize
;
1568 bcopy( s2_p
, &(wbuf
[icurs
]), iwordsize
) ; icurs
+= iwordsize
;
1569 bcopy( s3_p
, &(wbuf
[icurs
]), iwordsize
) ; icurs
+= iwordsize
;
1570 bcopy( s4_p
, &(wbuf
[icurs
]), iwordsize
) ; icurs
+= iwordsize
;
1571 bcopy( e1_p
, &(wbuf
[icurs
]), iwordsize
) ; icurs
+= iwordsize
;
1572 bcopy( e2_p
, &(wbuf
[icurs
]), iwordsize
) ; icurs
+= iwordsize
;
1573 bcopy( e3_p
, &(wbuf
[icurs
]), iwordsize
) ; icurs
+= iwordsize
;
1574 bcopy( e4_p
, &(wbuf
[icurs
]), iwordsize
) ; icurs
+= iwordsize
;
1576 rsl_swapbytes( wbuf
, iwordsize
, 9 ) ;
1584 i
= *ndim_p
; bcopy( &i
, &(wbuf
[icurs
]), iwordsize
/2 ) ; icurs
+= iwordsize
/2 ;
1585 i
= *s1_p
; bcopy( &i
, &(wbuf
[icurs
]), iwordsize
/2 ) ; icurs
+= iwordsize
/2 ;
1586 i
= *s2_p
; bcopy( &i
, &(wbuf
[icurs
]), iwordsize
/2 ) ; icurs
+= iwordsize
/2 ;
1587 i
= *s3_p
; bcopy( &i
, &(wbuf
[icurs
]), iwordsize
/2 ) ; icurs
+= iwordsize
/2 ;
1588 i
= *s4_p
; bcopy( &i
, &(wbuf
[icurs
]), iwordsize
/2 ) ; icurs
+= iwordsize
/2 ;
1589 i
= *e1_p
; bcopy( &i
, &(wbuf
[icurs
]), iwordsize
/2 ) ; icurs
+= iwordsize
/2 ;
1590 i
= *e2_p
; bcopy( &i
, &(wbuf
[icurs
]), iwordsize
/2 ) ; icurs
+= iwordsize
/2 ;
1591 i
= *e3_p
; bcopy( &i
, &(wbuf
[icurs
]), iwordsize
/2 ) ; icurs
+= iwordsize
/2 ;
1592 i
= *e4_p
; bcopy( &i
, &(wbuf
[icurs
]), iwordsize
/2 ) ; icurs
+= iwordsize
/2 ;
1595 rsl_swapbytes( wbuf
, iwordsize
/2, 9 ) ;
1600 bcopy( xtime_p
, &(wbuf
[icurs
]), rwordsize
) ;
1602 rsl_swapbytes( &(wbuf
[icurs
]), rwordsize
, 1 ) ;
1604 icurs
+= rwordsize
;
1606 { float x
; double y
;
1607 bcopy( xtime_p
, &y
, rwordsize
) ;
1609 bcopy( &x
, &(wbuf
[icurs
]), rwordsize
/2 ) ;
1612 rsl_swapbytes( &(wbuf
[icurs
]), rwordsize
/2, 1 ) ;
1614 icurs
+= rwordsize
/2 ;
1618 bcopy( staggering_p
, &(wbuf
[icurs
]),
1619 *nstaggering_p
) ; icurs
+= *nstaggering_p
;
1620 bcopy( ordering_p
, &(wbuf
[icurs
]),
1621 *nordering_p
) ; icurs
+= *nordering_p
;
1622 bcopy( current_date_p
, &(wbuf
[icurs
]),
1623 *ncurrent_date_p
) ; icurs
+= *ncurrent_date_p
;
1624 bcopy( name_p
, &(wbuf
[icurs
]),
1625 *nname_p
) ; icurs
+= *nname_p
;
1626 bcopy( units_p
, &(wbuf
[icurs
]),
1627 *nunits_p
) ; icurs
+= *nunits_p
;
1628 bcopy( description_p
, &(wbuf
[icurs
]),
1629 *ndescription_p
) ; icurs
+= *ndescription_p
;
1631 bcopy( _fcdtocp( staggering_p
) , &(wbuf
[icurs
]),
1632 *nstaggering_p
) ; icurs
+= *nstaggering_p
;
1633 bcopy( _fcdtocp( ordering_p
) , &(wbuf
[icurs
]),
1634 *nordering_p
) ; icurs
+= *nordering_p
;
1635 bcopy( _fcdtocp( current_date_p
), &(wbuf
[icurs
]),
1636 *ncurrent_date_p
) ; icurs
+= *ncurrent_date_p
;
1637 bcopy( _fcdtocp( name_p
) , &(wbuf
[icurs
]),
1638 *nname_p
) ; icurs
+= *nname_p
;
1639 bcopy( _fcdtocp( units_p
) , &(wbuf
[icurs
]),
1640 *nunits_p
) ; icurs
+= *nunits_p
;
1641 bcopy( _fcdtocp( description_p
) , &(wbuf
[icurs
]),
1642 *ndescription_p
) ; icurs
+= *ndescription_p
;
1645 if ( rsl_buffer_output
&& ! req
.internal
)
1647 if ( write_buffer_head
== NULL
&& write_buffer_tail
== NULL
)
1649 write_buffer_head
= RSL_MALLOC( rsl_write_buffer_struct_t
, 1 ) ;
1650 write_buffer_tail
= write_buffer_head
;
1654 write_buffer_tail
->next
= RSL_MALLOC( rsl_write_buffer_struct_t
, 1 ) ;
1655 write_buffer_tail
= write_buffer_tail
->next
;
1657 write_buffer_tail
->req
= req
;
1658 write_buffer_tail
->nelem
= nelem
;
1659 write_buffer_tail
->buf
= RSL_MALLOC( char, nelem
) ;
1660 bcopy( wbuf
, write_buffer_tail
->buf
, nelem
) ;
1664 send_to_output_device( &req
, wbuf
, nelem
) ;
1670 rsl_swapbytes ( buf
, wordsz
, nwords
)
1672 int wordsz
, nwords
;
1679 for ( i
= 0 ; i
< nwords
*wordsz
; i
+= wordsz
)
1681 tbuf
[0] = buf
[3+i
] ;
1682 tbuf
[1] = buf
[2+i
] ;
1683 tbuf
[2] = buf
[1+i
] ;
1684 tbuf
[3] = buf
[0+i
] ;
1685 buf
[0+i
] = tbuf
[0] ;
1686 buf
[1+i
] = tbuf
[1] ;
1687 buf
[2+i
] = tbuf
[2] ;
1688 buf
[3+i
] = tbuf
[3] ;
1691 else if ( wordsz
== 8 )
1693 for ( i
= 0 ; i
< nwords
*wordsz
; i
+= wordsz
)
1695 tbuf
[0] = buf
[7+i
] ;
1696 tbuf
[1] = buf
[6+i
] ;
1697 tbuf
[2] = buf
[5+i
] ;
1698 tbuf
[3] = buf
[4+i
] ;
1699 tbuf
[4] = buf
[3+i
] ;
1700 tbuf
[5] = buf
[2+i
] ;
1701 tbuf
[6] = buf
[1+i
] ;
1702 tbuf
[7] = buf
[0+i
] ;
1703 buf
[0+i
] = tbuf
[0] ;
1704 buf
[1+i
] = tbuf
[1] ;
1705 buf
[2+i
] = tbuf
[2] ;
1706 buf
[3+i
] = tbuf
[3] ;
1707 buf
[4+i
] = tbuf
[4] ;
1708 buf
[5+i
] = tbuf
[5] ;
1709 buf
[6+i
] = tbuf
[6] ;
1710 buf
[7+i
] = tbuf
[7] ;
1715 sprintf(mess
,"invalid argument wordsz = %d",wordsz
) ;
1716 RSL_TEST_ERR(1,mess
) ;
1720 RSL_WRITE_MM5V3_BIG_HEADER( unit_p
,
1725 iwordsize_p
,rwordsize_p
)
1727 char * ibuf
; int_p nibuf_p
;
1728 char * rbuf
; int_p nrbuf_p
;
1730 char * cb1
; int_p ncb1_p
;
1731 char * cb2
; int_p ncb2_p
;
1733 _fcd cb1
; int_p ncb1_p
;
1734 _fcd cb2
; int_p ncb2_p
;
1739 rsl_write_req_t req
;
1748 RSL_C_IAMMONITOR( &i_am_monitor
) ;
1749 if ( ! i_am_monitor
) return ;
1751 iwordsize
= *iwordsize_p
;
1752 rwordsize
= *rwordsize_p
;
1755 nelem
= *nibuf_p
* iwordsize
+
1756 *nrbuf_p
* rwordsize
+
1759 nelem
= *nibuf_p
* iwordsize
/2 +
1760 *nrbuf_p
* rwordsize
/2 +
1765 req
.request_type
= RSL_WRITE_REQUEST
;
1766 req
.request_mode
= MSG_IO_FORTRAN
;
1767 req
.unit
= *unit_p
;
1768 req
.unit_p
= unit_p
;
1769 req
.iotag
= IO_REPL
;
1770 req
.type
= RSL_CHARACTER
;
1772 wbuf
= RSL_MALLOC( char, nelem
) ;
1776 rsl_swapbytes( ibuf
, iwordsize
, *nibuf_p
) ;
1779 bcopy( ibuf
, &(wbuf
[icurs
]), *nibuf_p
* iwordsize
) ;
1780 icurs
+= *nibuf_p
* iwordsize
;
1783 { long *p
; int *q
; int i
;
1787 { long *p
; short *q
; int i
;
1789 q
= (short *) ibuf
;
1791 for ( i
= 0 ; i
< *nibuf_p
; i
++ )
1793 *q
= *p
; q
++ ; p
++ ;
1796 bcopy( ibuf
, &(wbuf
[icurs
]), *nibuf_p
* iwordsize
/2 ) ;
1797 icurs
+= *nibuf_p
* iwordsize
/ 2 ;
1800 rsl_swapbytes( rbuf
, rwordsize
, *nrbuf_p
) ;
1803 bcopy( rbuf
, &(wbuf
[icurs
]), *nrbuf_p
* rwordsize
) ;
1804 icurs
+= *nrbuf_p
* rwordsize
;
1806 { double *p
; float *q
; int i
;
1807 p
= (double *) rbuf
;
1808 q
= (float *) rbuf
;
1809 for ( i
= 0 ; i
< *nrbuf_p
; i
++ )
1811 *q
= *p
; q
++ ; p
++ ;
1814 bcopy( rbuf
, &(wbuf
[icurs
]), *nrbuf_p
* rwordsize
/2 ) ;
1815 icurs
+= *nrbuf_p
* rwordsize
/ 2 ;
1818 bcopy( cb1
, &(wbuf
[icurs
]), *ncb1_p
) ; icurs
+= *ncb1_p
;
1819 bcopy( cb2
, &(wbuf
[icurs
]), *ncb2_p
) ; icurs
+= *ncb2_p
;
1821 bcopy( _fcdtocp( cb1
), &(wbuf
[icurs
]), *ncb1_p
) ; icurs
+= *ncb1_p
;
1822 bcopy( _fcdtocp( cb2
), &(wbuf
[icurs
]), *ncb2_p
) ; icurs
+= *ncb2_p
;
1824 if ( rsl_buffer_output
&& ! req
.internal
)
1826 if ( write_buffer_head
== NULL
&& write_buffer_tail
== NULL
)
1828 write_buffer_head
= RSL_MALLOC( rsl_write_buffer_struct_t
, 1 ) ;
1829 write_buffer_tail
= write_buffer_head
;
1833 write_buffer_tail
->next
= RSL_MALLOC( rsl_write_buffer_struct_t
, 1 ) ;
1834 write_buffer_tail
= write_buffer_tail
->next
;
1836 write_buffer_tail
->req
= req
;
1837 write_buffer_tail
->nelem
= nelem
;
1838 write_buffer_tail
->buf
= RSL_MALLOC( char, nelem
) ;
1839 bcopy( wbuf
, write_buffer_tail
->buf
, nelem
) ;
1843 send_to_output_device( &req
, wbuf
, nelem
) ;