From: Martial Michel <martial@nist.gov>
Newsgroups: comp.parallel.mpi
Subject: Re: user-defined datatypes
Date: 03 Dec 1998 19:10:49 -0500
Organization: National Institute of Standards & Technology
Message-Id: <mu67lw8kbqu.fsf@miyu.cam.nist.gov>
References: <3666DF91.CFAFB050@ecs.soton.ac.uk>


	Hi,

	We have developped a tool called AutoMap, available at :
http://www.nist.gov/itl/div895/auto/
	that aims is to create such "complex" data-types.

You may just have to update your structure definitions as follow :

----------
/*~ AM_Begin */

struct _type1
{
  float x, y;
};

typedef struct _type1 type1 /*~ AM */;

struct _type2
{
  int   c;
  type1  d;
};

typedef struct _type2 type2 /*~ AM */;

/*~ AM_End */
----------

The changes are that  you are using data-types  and AutoMap markers in
your data-types definition.

Then you can use it into AutoMap (a  "on the web" version is available
if your operating  system is not one of  the supported ones), and  you
will get some output  files containing a command "Build_MPI_Types"  to
run after your "MPI_Init" command, that will make available to you two
new  MPI_DataType :  MPI_type1  and MPI_type2 (note   that in the next
release, that should be out before end of december, that is changed to
AM_type1 and AM_type2).

Here is the code you may require for your example :
----------
MPI_Datatype         AM_type1;
MPI_Datatype         AM_type2;

#define MaxFields   50

void
Build_MPI_Types()
{

  type1 Type0;
  type2 Type1;

  MPI_Aint          disp[MaxFields];
  MPI_Datatype      type[MaxFields];
  int               blocklen[MaxFields];
  int               base;
  int               i;

 /* type1 */
  MPI_Address(&Type0.x,	&disp[0]);
  MPI_Address(&Type0.y,	&disp[1]);
  type[0] = MPI_FLOAT;
  type[1] = MPI_FLOAT;
  blocklen[0] = 1;
  blocklen[1] = 1;
  base = disp[0];
  for (i=0; i<2; i++)
    disp[i]-=base;
  MPI_Type_struct(2, blocklen, disp, type, &AM_type1);
  MPI_Type_commit(&AM_type1);

 /* type2 */
  MPI_Address(&Type1.c,	&disp[0]);
  MPI_Address(&Type1.d,	&disp[1]);
  type[0] = MPI_INT;
  type[1] = AM_type1;
  blocklen[0] = 1;
  blocklen[1] = 1;
  base = disp[0];
  for (i=0; i<2; i++)
    disp[i]-=base;
  MPI_Type_struct(2, blocklen, disp, type, &AM_type2);
  MPI_Type_commit(&AM_type2);
}
----------

							Sincerely,

PS : For further questions, please send me E-mail (address is below)

-- 
  Martial MICHEL
Guest Researcher at the National Institute of Standards and Technology
E-mail : martial.michel@nist.gov
Phone  : (301) 975 3866 (Maryland, USA)

