[LUGSB] INTs as BYTEs in MPI

John R. Hover jhover at ic.sunysb.edu
Mon May 16 13:48:04 EDT 2005


If I understand your question, it looks like you'll face two issues:

1) sizeof(int) != sizeof(byte) on most platforms, since an int is 
typically 4 bytes and a byte is 1 byte. So to get that last 4-byte value 
into the 5th position in the int_array you'll have to do *some* kind of 
packing--either use a struct for the whole thing, or do bit-shifting 
e.g. something like:

//to send
int tmp;
tmp = b1;
tmp = tmp << 8;

tmp = b2 | tmp;
tmp = tmp << 8;

tmp = b3 | tmp;
tmp = tmp << 8;

tmp = b4 | tmp;
int_array[5] = tmp;

Then, yes on the other end you can do your
*byte_array = &int_array[5]

2) More tricky is the question of whether the sending and receiving 
system have the same endianness. If they don't (or you're writing code 
that *might* need to run someday on ones that don't), then the code 
above won't work. Presumably, the MPI code for sending int/byte arrays 
does the Right Thing, but you're trying to make an end run (no pun 
intended) around their API. :-)

So, my recommendation ( unless you want to enter the twilight zone ) is 
to just use whatever native MPI API calls are available. Once you have 
fully debugged and working code, if you need greater speed/efficiency, 
then consider customizing your use of the API.

--john

Lucas Carey wrote:
> Hey you real computer science  people,
> I'm writing an MPI program, and I want to condense two sends down into one. For those of you who don't know, MPI allows interprocess communication across computers. One of these sends is an array of INTs, the other an array of BYTEs. If I throw the bytes into the int array, can I reinterpret them as bytes later on, as I know the offset from which they will start in the int array.
> currently:
> *int_array = [0,1,2,3,4]
> *byte_array = [b1,b2,b3,b4]
> 
> want:
> *int_array = [0,1,2,3,4,b1,b2,b3,b4]
> *byte_array = &int_array[5]
> 
> or something like that. I know I can send the data as a struct, but I prefer to avoid having to pack the data up to send it.
> Are there any platforms where sizeof(int)!=sizeof(byte) where this might break?
> -Lucas
> 
> 
> _______________________________________________
> lugsb mailing list
> lugsb at mail.fsl.cs.sunysb.edu
> http://www.fsl.cs.sunysb.edu/mailman/listinfo/lugsb



More information about the lugsb mailing list