@@ -334,18 +334,16 @@ END
334
334
(define MPI:make-type-struct
335
335
(foreign-primitive scheme-object ((int fieldcount)
336
336
(scheme-object blocklens)
337
- (scheme-object displs)
338
337
(scheme-object fieldtys))
339
338
#<<EOF
340
- int i, status;
339
+ int i, status, fldtysize ;
341
340
int *array_of_blocklens;
342
341
MPI_Aint *array_of_displs;
343
342
MPI_Datatype *array_of_types, newtype;
344
343
chicken_MPI_datatype_t newdatatype;
345
344
C_word result, x, tail;
346
345
347
346
C_i_check_list (blocklens);
348
- C_i_check_list (displs);
349
347
C_i_check_list (fieldtys);
350
348
351
349
if (!(fieldcount > 0 ))
@@ -364,30 +362,32 @@ END
364
362
tail = C_u_i_cdr (tail);
365
363
array_of_blocklens[i] = C_num_to_int(x);
366
364
}
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
- }
374
365
tail = fieldtys;
375
366
for (i=0; i<fieldcount; i++)
376
367
{
377
368
x = C_u_i_car (tail);
378
369
tail = C_u_i_cdr (tail);
379
370
array_of_types[i] = Datatype_val(x);
380
371
}
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
+ }
381
384
382
385
status = MPI_Type_create_struct(fieldcount,
383
386
array_of_blocklens,
384
387
array_of_displs,
385
388
array_of_types,
386
389
&newtype);
387
390
388
- free(array_of_blocklens);
389
- free(array_of_displs);
390
- free(array_of_types);
391
391
392
392
if (status != MPI_SUCCESS)
393
393
{
405
405
newdatatype.datatype_data = (void *)newtype;
406
406
result = (C_word)&newdatatype;
407
407
408
+ free(array_of_blocklens);
409
+ free(array_of_displs);
410
+ free(array_of_types);
411
+
408
412
C_return(result);
409
413
EOF
410
414
))
0 commit comments