Skip to content

Commit

Permalink
Merge branch 'datatype'
Browse files Browse the repository at this point in the history
  • Loading branch information
iraikov committed Jun 21, 2016
2 parents 6a14073 + 0845bbc commit ce31927
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
30 changes: 17 additions & 13 deletions datatype.scm
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,16 @@ END
(define MPI:make-type-struct
(foreign-primitive scheme-object ((int fieldcount)
(scheme-object blocklens)
(scheme-object displs)
(scheme-object fieldtys))
#<<EOF
int i, status;
int i, status, fldtysize;
int *array_of_blocklens;
MPI_Aint *array_of_displs;
MPI_Datatype *array_of_types, newtype;
chicken_MPI_datatype_t newdatatype;
C_word result, x, tail;

C_i_check_list (blocklens);
C_i_check_list (displs);
C_i_check_list (fieldtys);

if (!(fieldcount > 0))
Expand All @@ -364,30 +362,32 @@ END
tail = C_u_i_cdr (tail);
array_of_blocklens[i] = C_num_to_int(x);
}
tail = displs;
for (i=0; i<fieldcount; i++)
{
x = C_u_i_car (tail);
tail = C_u_i_cdr (tail);
array_of_displs[i] = C_num_to_int(x);
}
tail = fieldtys;
for (i=0; i<fieldcount; i++)
{
x = C_u_i_car (tail);
tail = C_u_i_cdr (tail);
array_of_types[i] = Datatype_val(x);
}
array_of_displs[0] = 0;
for (i=1; i<fieldcount; i++)
{
status = MPI_Type_size(array_of_types[i-1], &fldtysize);

if (status != MPI_SUCCESS)
{
chicken_MPI_exception (MPI_ERR_TYPE, 20, "invalid MPI datatype");
}

array_of_displs[i] = array_of_displs[i-1] + fldtysize * array_of_blocklens[i-1];
}

status = MPI_Type_create_struct(fieldcount,
array_of_blocklens,
array_of_displs,
array_of_types,
&newtype);

free(array_of_blocklens);
free(array_of_displs);
free(array_of_types);

if (status != MPI_SUCCESS)
{
Expand All @@ -405,6 +405,10 @@ END
newdatatype.datatype_data = (void *)newtype;
result = (C_word)&newdatatype;

free(array_of_blocklens);
free(array_of_displs);
free(array_of_types);

C_return(result);
EOF
))
Expand Down
6 changes: 3 additions & 3 deletions tests/datatest.scm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
(define (blob-concatenate data extent)
(let ((buf (make-blob (* extent (length data)))))
(fold
(lambda (b i) (move-memory! b buf (blob-size b) 0 (* i extent)) (+ i 1))
(lambda (b i)
(move-memory! b buf (blob-size b) 0 (* i extent)) (+ i 1))
0 data)
buf))

Expand All @@ -22,7 +23,6 @@

(define nflds 3)
(define blocklens '(10 1 1))
(define displs '(0 10 14))
(define fieldtys `(,MPI:type-char ,MPI:type-u32 ,MPI:type-f64))

(if (zero? myrank)
Expand All @@ -31,7 +31,7 @@
(print "extent of MPI char type is " (MPI:type-extent MPI:type-char))
))

(define newty (MPI:make-type-struct nflds blocklens displs fieldtys))
(define newty (MPI:make-type-struct nflds blocklens fieldtys))
(define tysize (MPI:type-size newty))

(if (zero? myrank)
Expand Down

0 comments on commit ce31927

Please sign in to comment.