Newsgroups: comp.parallel.pvm
From: ijb@mserv1.dl.ac.uk (I.J. Bush)
Subject: Re: packing and unpacking commons
Organization: Daresbury Laboratory, UK
Date: 13 Sep 1994 16:09:51 GMT
Message-ID: <354isf$npq@mserv1.dl.ac.uk>

In article 94Sep12130215@smithers.et.byu.edu, dave@smithers.et.byu.edu (David L. Peart) writes:
> Is there a simple way to pack and unpack commons.  I have many commons
> that must be sent between slaves that are a major pain to work with
> variable by variable.
> 
> thank you,
> --
> David L. Peart
> ACERC CCL Systems Manager
> Brigham Young University
> dave@byu.edu
> 



Yes you can, well at least if

i)  Your system is homogeneous ( i.e. you do not need to XDR encode )
ii) You can put up with some very nasty Fortran !

The point is that Fortran by default has no array bound checking, has
no checking of data types when they are passed ( I assume you are using
Fortran 77, Fortran 90 is a bit trickier ) and
also that common blocks are stored contiguously in memory. If you then
pass the first element of the common block to a routine, declare it as
an array of characters ( or whatever takes up one byte in your machine )
of size 1 and then unpack the whole lot into this array. On return you will have
filled up the common block e.g. for unpacking



      PROGRAM horrible_Fortran

      INTEGER          a( 1:2 ), b, more_rubbish( 1:3 )
      DOUBLE PRECISION vital_data( 1:10 )

      COMMON /nobel_prize/ a, b, more_rubbish, vital_data

      INTEGER size_of_common

.......
      recv message
.......
      size_of_common = ( 2 + 1 + 3 ) * 4 + 10 * 8   ! I am assuming a 32 bit machine
                                                    ! Of course parameters
                                                    ! for these sizes would be better.
      CALL unpack_common( a( 1 ), size_of_common )

........

      END


      SUBROUTINE( common_block, size_of_common )

      INCLUDE 'fpvm.h'


      CHARACTER*1 common_block( 1:1 )
      INTEGER     size_of_common      
 
      INTEGER     info

      CALL pvmfunpack( STRING, common_block, size_of_common, 1, info )      
.....Test info

      END


I haven't actually tested this but I don't see why it shouldn't work. If it will
not please tell me why ! I also don't know how XDR encoding will affect it,
but I suspect it just wouldn't work

yours hopefully helpfully


Ian


---
---------------------------------------------------------------------------
JANET:            I.J.Bush@uk.ac.daresbury           Phone: 0925 603652
JANETVAXMAIL:     cbs%uk.ac.daresbury::I.J.Bush      FAX: 0925 60????
Internet:         I.J.Bush@daresbury.ac.uk           Address: DRAL
EARN/BITNET:      I.J.Bush%daresbury.ac.uk@ukacrl    Daresbury Laboratory
UUCP:             I.J.Bush%daresbury.ac.uk@ukc.uucp  Warrington 
EAN/X400:         I.J.Bush@daresbury.ac.uk           WA4 4AD
--------------------------------------------------------------------------



