Skip to content

Commit ce31927

Browse files
committed
Merge branch 'datatype'
2 parents 6a14073 + 0845bbc commit ce31927

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

datatype.scm

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,18 +334,16 @@ END
334334
(define MPI:make-type-struct
335335
(foreign-primitive scheme-object ((int fieldcount)
336336
(scheme-object blocklens)
337-
(scheme-object displs)
338337
(scheme-object fieldtys))
339338
#<<EOF
340-
int i, status;
339+
int i, status, fldtysize;
341340
int *array_of_blocklens;
342341
MPI_Aint *array_of_displs;
343342
MPI_Datatype *array_of_types, newtype;
344343
chicken_MPI_datatype_t newdatatype;
345344
C_word result, x, tail;
346345

347346
C_i_check_list (blocklens);
348-
C_i_check_list (displs);
349347
C_i_check_list (fieldtys);
350348

351349
if (!(fieldcount > 0))
@@ -364,30 +362,32 @@ END
364362
tail = C_u_i_cdr (tail);
365363
array_of_blocklens[i] = C_num_to_int(x);
366364
}
367-
tail = displs;
368-
for (i=0; i<fieldcount; i++)
369-
{
370-
x = C_u_i_car (tail);
371-
tail = C_u_i_cdr (tail);
372-
array_of_displs[i] = C_num_to_int(x);
373-
}
374365
tail = fieldtys;
375366
for (i=0; i<fieldcount; i++)
376367
{
377368
x = C_u_i_car (tail);
378369
tail = C_u_i_cdr (tail);
379370
array_of_types[i] = Datatype_val(x);
380371
}
372+
array_of_displs[0] = 0;
373+
for (i=1; i<fieldcount; i++)
374+
{
375+
status = MPI_Type_size(array_of_types[i-1], &fldtysize);
376+
377+
if (status != MPI_SUCCESS)
378+
{
379+
chicken_MPI_exception (MPI_ERR_TYPE, 20, "invalid MPI datatype");
380+
}
381+
382+
array_of_displs[i] = array_of_displs[i-1] + fldtysize * array_of_blocklens[i-1];
383+
}
381384

382385
status = MPI_Type_create_struct(fieldcount,
383386
array_of_blocklens,
384387
array_of_displs,
385388
array_of_types,
386389
&newtype);
387390

388-
free(array_of_blocklens);
389-
free(array_of_displs);
390-
free(array_of_types);
391391

392392
if (status != MPI_SUCCESS)
393393
{
@@ -405,6 +405,10 @@ END
405405
newdatatype.datatype_data = (void *)newtype;
406406
result = (C_word)&newdatatype;
407407

408+
free(array_of_blocklens);
409+
free(array_of_displs);
410+
free(array_of_types);
411+
408412
C_return(result);
409413
EOF
410414
))

tests/datatest.scm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
(define (blob-concatenate data extent)
99
(let ((buf (make-blob (* extent (length data)))))
1010
(fold
11-
(lambda (b i) (move-memory! b buf (blob-size b) 0 (* i extent)) (+ i 1))
11+
(lambda (b i)
12+
(move-memory! b buf (blob-size b) 0 (* i extent)) (+ i 1))
1213
0 data)
1314
buf))
1415

@@ -22,7 +23,6 @@
2223

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

2828
(if (zero? myrank)
@@ -31,7 +31,7 @@
3131
(print "extent of MPI char type is " (MPI:type-extent MPI:type-char))
3232
))
3333

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

3737
(if (zero? myrank)

0 commit comments

Comments
 (0)