{ GPC interface to the MPI library.

  Original FPC code by Persio Leister de Almeida Barros.
  Modification for version 6.5.6 of LAM MPI by Cas Cremers

  Translation to GPC  and additional MPI Structures and Functions by
  Silvio a Beccara - University of Trento, Italy -  2002

  This version does not require LAM/MPI 6.5, but has been
  (unthoroughly) tested on 6.5.6 only. Testing and comments are
  welcome.

  Copyright 2002 Silvio a Beccara <abeccara@science.unitn.it>

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License as
  published by the Free Software Foundation, version 2.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; see the file COPYING. If not, write to
  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA. }

unit mpiwrap;

interface

const
MPI_MAX_OBJECT_NAME=64;
MPI_ANY_SOURCE= -1;
MPI_ANY_TAG = -1;

type

c_int= integer;

c_int4= integer;
c_int8= record
   low, high: integer;
   end;
c_long= MedInt;
//c_long= c_int8;




MPI_Group= ^m_group;
m_group= record
   g_nprocs: c_int;
   g_myrank: c_int;
   g_refcount: c_int;
   g_f77handle: c_int;
   g_procs: pointer {to be completed. see rpisys.h}
   end;

cmp_func= function: c_int;
ah_desc= record
	ah_maxnelem: c_int4;
	ah_nelem: c_int4;
	ah_elemsize: c_int4;
	ah_nullkey: c_int4;
	ah_mode: c_int4;
	ah_lru: ^c_int4;
	ah_table: pointer;
	ah_cmp: cmp_func;
        end;
HASH= ah_desc;

m_osdhdr= record
   os_func: c_int;
   os_op: c_int;
   os_count: c_int;
   os_format: c_int;
   os_type: c_int;
   os_blklen: c_int;
   os_stride: c_int;
   os_pad: c_int;
   os_disp: c_int8;
   end;

MPI_Aint= c_long;

//MPI_Request= pointer;  {^_req} {To be completed. See rpisys.h}


MPI_Request= c_int;  {^_req} {To be completed. See rpisys.h}

errfunc= procedure;
MPI_Errhandler= ^m_errhdl;
m_errhdl= record
   eh_func: errfunc;
   eh_f77handle: c_int;
   eh_flags: c_int;
   end;



redfunc= procedure;
MPI_Op= ^m_op;
m_op=record
   op_func: redfunc;
   op_commute: c_int;
   op_f77handle: c_int;
   op_flags: c_int;
   end;


MPI_Comm= ^m_comm;
MPI_Win= ^m_window;
m_window=record
   w_comm: MPI_Comm;
   w_base: pointer;
   w_size: MPI_Aint;
   w_disp_unit: c_int;
   w_flags: c_int;
   w_ngroup: c_int;
   w_ncomplete: c_int;
   w_nfence: c_int;
   w_pstate: ^c_int;
   w_f77handler: c_int;
   w_keys: ^HASH;
   w_req: MPI_Request;
   w_header: m_osdhdr;
   w_errhdl: MPI_Errhandler;
   w_reserved: array[1..4] of c_long;
   end;



m_comm= record
    c_flags: c_int;
    c_contextid: c_int;
    c_refcount: c_int;
    c_group: MPI_Group;
    c_rgroup: MPI_Group;
    c_keys: ^HASH;
    c_cube_dim: c_int;
    c_topo_type: c_int;
    c_topo_nprocs: c_int;
    c_topo_ndims: c_int;
    c_topo_nedges: c_int;
    c_topo_dims: ^c_int;
    c_topo_coords: ^c_int;
    c_topo_index: ^c_int;
    c_topo_edges: ^c_int;
    c_f77handle: c_int;
    c_window:  MPI_Win;
    c_errhdl: MPI_Errhandler;
    c_name: array[1..MPI_MAX_OBJECT_NAME] of char;
    c_shadow: MPI_Comm;
    c_reserved: array[1..4] of c_long;
    end;



MPI_Datatype= ^m_dtype;
m_dtype= record
   dt_format: c_int;
   dt_flags: c_int;
   dt_commit: c_int;
   dt_refcount: c_int;
   dt_f77handle: c_int;
   dt_label: c_int;
   dt_align: c_int;
   dt_upper: c_int;
   dt_lower: c_int;
   dt_size: c_int;
   dt_dataup: c_int;
   dt_datalow: c_int;
   dt_nelem: c_int;
   dt_count: c_int;
   dt_length: c_int;
   dt_stride: MPI_Aint;
   dt_dtype: MPI_Datatype;
   dt_lengths: ^c_int;
   dt_disps: ^MPI_Aint;
   dt_dtypes: ^MPI_Datatype;
   dt_keys: ^HASH;
   dt_uargs: ^c_int;
   dt_name: array[1..MPI_MAX_OBJECT_NAME] of char;
   dt_reserved: array[1..4] of c_long;
   end;

m_status= record
   MPI_SOURCE: c_int;
   MPI_TAG: c_int;
   MPI_ERROR: c_int;
   st_length: c_int;
   end;
MPI_STATUS= m_status;



//datapointer=^MPI_DATATYPE;



var

lam_mpi_comm_world: m_comm; asmname 'lam_mpi_comm_world';
lam_mpi_comm_self: m_comm; asmname 'lam_mpi_comm_self';
lam_mpi_max: m_op; asmname 'lam_mpi_max';
lam_mpi_min: m_op; asmname 'lam_mpi_min';
lam_mpi_sum: m_op; asmname 'lam_mpi_sum';
lam_mpi_prod: m_op;  asmname 'lam_mpi_prod';
lam_mpi_land: m_op;  asmname 'lam_mpi_land';
lam_mpi_band: m_op;  asmname 'lam_mpi_band';
lam_mpi_lor: m_op;  asmname 'lam_mpi_lor';
lam_mpi_bor: m_op;  asmname 'lam_mpi_bor';
lam_mpi_lxor:  m_op; asmname 'lam_mpi_lxor';
lam_mpi_bxor:  m_op; asmname 'lam_mpi_bxor';
lam_mpi_maxloc: m_op;  asmname 'lam_mpi_maxloc';
lam_mpi_minloc: m_op;  asmname 'lam_mpi_minloc';
lam_mpi_byte: m_dtype;  asmname 'lam_mpi_byte';
lam_mpi_packed: m_dtype;  asmname 'lam_mpi_packed';
lam_mpi_char: m_dtype;  asmname 'lam_mpi_char';
lam_mpi_short: m_dtype;  asmname 'lam_mpi_short';
lam_mpi_int: m_dtype;  asmname 'lam_mpi_int';
lam_mpi_long: m_dtype;  asmname 'lam_mpi_long';
lam_mpi_float: m_dtype;  asmname 'lam_mpi_float';
lam_mpi_double: m_dtype;  asmname 'lam_mpi_double';
lam_mpi_long_double: m_dtype;  asmname 'lam_mpi_long_double';
lam_mpi_unsigned_char: m_dtype;  asmname 'lam_mpi_unsigned_char';
lam_mpi_unsigned_short: m_dtype;  asmname 'lam_mpi_unsigned_short';
lam_mpi_unsigned_long: m_dtype;  asmname 'lam_mpi_unsigned_long';
lam_mpi_unsigned: m_dtype;  asmname 'lam_mpi_unsigned';
lam_mpi_float_int: m_dtype;  asmname 'lam_mpi_float_int';
lam_mpi_double_int: m_dtype;  asmname 'lam_mpi_double_int';
lam_mpi_longdbl_int: m_dtype;  asmname 'lam_mpi_longdbl_int';
lam_mpi_long_int: m_dtype;  asmname 'lam_mpi_long_int';
lam_mpi_short_int: m_dtype;  asmname 'lam_mpi_short_int';
lam_mpi_2int: m_dtype;  asmname 'lam_mpi_2int';
lam_mpi_ub: m_dtype;  asmname 'lam_mpi_ub';
lam_mpi_lb: m_dtype;  asmname 'lam_mpi_lb';
lam_mpi_wchar: m_dtype;  asmname 'lam_mpi_wchar';
lam_mpi_long_long_int: m_dtype;  asmname 'lam_mpi_long_long_int';
lam_mpi_unsigned_long_long: m_dtype;  asmname 'lam_mpi_unsigned_long_long';



function MPI_Init( i, j: pointer ): c_int; asmname 'MPI_Init';

function MPI_Comm_size(comm: MPI_Comm; var size: c_int): c_int; asmname 'MPI_Comm_size';
function MPI_Comm_rank(comm: MPI_Comm; var rank: c_int): c_int; asmname 'MPI_Comm_rank';

function MPI_Send(buff: pointer; buffsize: c_int; MPI_TYPE: MPI_DATATYPE;
     i, j: c_int; comm: MPI_Comm): c_int; asmname 'MPI_Send';


function MPI_Recv(buff: pointer; buffsize: c_int; MPI_TYPE: MPI_DATATYPE;
     i, j: c_int; comm: MPI_Comm; var status: MPI_STATUS): c_int; asmname 'MPI_Recv';


function MPI_Isend(buff: pointer; buffsize: c_int; MPI_TYPE: MPI_DATATYPE;
     i, j: c_int; comm: MPI_Comm; var request: MPI_Request): c_int; asmname 'MPI_Isend';

function MPI_Irecv(buff: pointer; buffsize: c_int; MPI_TYPE: MPI_DATATYPE;
     i, j: c_int; comm: MPI_Comm; var status: MPI_STATUS; var request: MPI_Request): c_int; asmname 'MPI_Irecv';


function MPI_Wait ( var request: MPI_REQUEST; var status: MPI_STATUS ): c_int; asmname 'MPI_Wait';

function MPI_Test ( var request: MPI_REQUEST; var done: c_int; var status: MPI_STATUS): c_int; asmname 'MPI_Test';


function MPI_Reduce (sendbuf, recvbuf: pointer; count: c_int; MPI_TYPE: MPI_DATATYPE; op: MPI_Op; root: c_int; comm: MPI_Comm): c_int; asmname 'MPI_Reduce';

function MPI_Bcast ( buffer: pointer;  count: c_int; MPI_TYPE: MPI_DATATYPE; root: c_int; comm: MPI_Comm ): c_int; asmname 'MPI_Bcast';

function MPI_Gather ( sendbuf: pointer; sendcount: c_int; sendtype: MPI_DATATYPE; recvbuf: pointer; recvcount: c_int; recvtype: MPI_DATATYPE; root: c_int; comm: MPI_COMM): c_int; asmname 'MPI_Gather';

function MPI_GatherV ( sendbuf: pointer; sendcount: c_int; sendtype: MPI_DATATYPE; recvbuf: pointer; recvcounts: pointer; displs: pointer; recvtype: MPI_DATATYPE; root: c_int; comm: MPI_COMM): c_int; asmname 'MPI_Gatherv';


function MPI_Scatter ( sendbuf: pointer; sendcount: c_int; sendtype: MPI_DATATYPE; recvbuf: pointer; recvcount: c_int; recvtype: MPI_DATATYPE; root: c_int; comm: MPI_COMM): c_int; asmname 'MPI_Scatter';

function MPI_ScatterV ( sendbuf: pointer; sendcounts: pointer; displs: pointer; sendtype: MPI_DATATYPE; recvbuf: pointer; recvcount: c_int; recvtype: MPI_DATATYPE; root: c_int; comm: MPI_COMM): c_int; asmname 'MPI_Scatterv';


function MPI_Barrier ( comm: MPI_COMM ): c_int; asmname 'MPI_Barrier';

function MPI_Finalize: c_int;  asmname 'MPI_Finalize';

//function MPI_Wait ( request, status: c_int ): c_int; asmname 'MPI_Wait';

function MPI_Type_contiguous ( count: c_int; oldtype: MPI_DATATYPE; newtype: pointer ): c_int; asmname 'MPI_Type_contiguous';

function MPI_Type_vector ( count: c_int; blocklength: c_int; stride: c_int; oldtype: MPI_DATATYPE; newtype: pointer ): c_int; asmname 'MPI_Type_vector';

function MPI_Type_commit ( newtype: pointer ): c_int; asmname 'MPI_Type_commit';

function MPI_Type_free ( newtype: pointer ): c_int;  asmname 'MPI_Type_free';

function MPI_Get_count ( var status: MPI_STATUS; datatype: MPI_DATATYPE; var count: c_int ): c_int; asmname 'MPI_Get_count';

function MPI_Pack ( inbuf: pointer; incount: c_int; datatype: MPI_DATATYPE; outbuf: pointer; outcount: c_int; var position: c_int; comm: MPI_COMM ): c_int; asmname 'MPI_Pack';

function MPI_Unpack ( inbuf: pointer; insize: c_int; var position: c_int; outbuf: pointer; outcount: c_int; datatype: MPI_DATATYPE; comm: MPI_COMM ): c_int; asmname 'MPI_Unpack';





const

MPI_COMM_WORLD: MPI_Comm = addr(lam_mpi_comm_world);
MPI_COMM_SELF: MPI_Comm= addr(lam_mpi_comm_self);
MPI_MAX: MPI_Op= addr (lam_mpi_max);
MPI_MIN: MPI_Op= addr (lam_mpi_min);
MPI_SUM: MPI_Op= addr(lam_mpi_sum);
MPI_PROD: MPI_Op= addr (lam_mpi_prod);
MPI_LAND: MPI_Op= addr (lam_mpi_land);
MPI_BAND: MPI_Op= addr (lam_mpi_band);
MPI_LOR: MPI_Op= addr (lam_mpi_lor);
MPI_BOR: MPI_Op= addr (lam_mpi_bor);
MPI_LXOR: MPI_Op= addr (lam_mpi_lxor);
MPI_BXOR: MPI_Op= addr (lam_mpi_bxor);
MPI_MAXLOC: MPI_Op= addr (lam_mpi_maxloc);
MPI_MINLOC: MPI_Op= addr (lam_mpi_minloc);
MPI_BYTE: MPI_Datatype= addr(lam_mpi_byte);
MPI_PACKED: MPI_Datatype= addr(lam_mpi_packed);
MPI_CHAR: MPI_Datatype= addr(lam_mpi_char);
MPI_SHORT: MPI_Datatype= addr(lam_mpi_short);
MPI_INT: MPI_Datatype= addr(lam_mpi_int);
MPI_LONG: MPI_Datatype= addr(lam_mpi_long);
MPI_FLOAT: MPI_Datatype= addr(lam_mpi_float);
MPI_DOUBLE: MPI_Datatype= addr(lam_mpi_double);
MPI_LONG_DOUBLE: MPI_Datatype= addr(lam_mpi_long_double);
MPI_UNSIGNED_CHAR: MPI_Datatype= addr(lam_mpi_unsigned_char);
MPI_UNSIGNED_SHORT: MPI_Datatype= addr(lam_mpi_unsigned_short);
MPI_UNSIGNED_LONG: MPI_Datatype= addr(lam_mpi_unsigned_long);
MPI_UNSIGNED: MPI_Datatype= addr(lam_mpi_unsigned);
MPI_FLOAT_INT: MPI_Datatype= addr(lam_mpi_float_int);
MPI_DOUBLE_INT: MPI_Datatype= addr(lam_mpi_double_int);
MPI_LONG_DOUBLE_INT: MPI_Datatype= addr(lam_mpi_longdbl_int);
MPI_LONG_INT: MPI_Datatype= addr(lam_mpi_long_int);
MPI_SHORT_INT: MPI_Datatype= addr(lam_mpi_short_int);
MPI_2INT: MPI_Datatype= addr(lam_mpi_2int);
MPI_UB: MPI_Datatype= addr(lam_mpi_ub);
MPI_LB: MPI_Datatype= addr(lam_mpi_lb);
MPI_WCHAR: MPI_Datatype= addr(lam_mpi_wchar);
MPI_LONG_LONG_INT: MPI_Datatype= addr(lam_mpi_long_long_int);
MPI_UNSIGNED_LONG_LONG: MPI_Datatype= addr(lam_mpi_unsigned_long_long);




implementation

{$L mpi}
{$L lam}



begin
end.

