Add a corner case for struct with multiple predefined types.
Cleanup the datatypes once they are not useful. Other minor fixes.
Этот коммит содержится в:
родитель
e26e7ad736
Коммит
267fdfe435
@ -51,14 +51,20 @@ main(int argc, char* argv[])
|
|||||||
void *payload, *ptr;
|
void *payload, *ptr;
|
||||||
struct ompi_datatype_t *unpacked_dt;
|
struct ompi_datatype_t *unpacked_dt;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int blen[2];
|
int blen[4];
|
||||||
MPI_Aint disp[2];
|
MPI_Aint disp[4];
|
||||||
MPI_Datatype newType, types[2], struct_type, vec_type;
|
MPI_Datatype newType, types[4], struct_type, vec_type;
|
||||||
MPI_Aint old_lb, old_extent, old_true_lb, old_true_extent;
|
MPI_Aint old_lb, old_extent, old_true_lb, old_true_extent;
|
||||||
MPI_Aint lb, extent, true_lb, true_extent;
|
MPI_Aint lb, extent, true_lb, true_extent;
|
||||||
|
|
||||||
MPI_Init(&argc, &argv);
|
MPI_Init(&argc, &argv);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* TEST 1
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
/* Basic test... */
|
/* Basic test... */
|
||||||
printf("---> Basic test with MPI_INT\n");
|
printf("---> Basic test with MPI_INT\n");
|
||||||
|
|
||||||
@ -66,9 +72,10 @@ main(int argc, char* argv[])
|
|||||||
ptr = payload = malloc(packed_ddt_len);
|
ptr = payload = malloc(packed_ddt_len);
|
||||||
ret = ompi_datatype_get_pack_description(MPI_INT, &packed_ddt);
|
ret = ompi_datatype_get_pack_description(MPI_INT, &packed_ddt);
|
||||||
if (ret != 0) goto cleanup;
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
memcpy(payload, packed_ddt, packed_ddt_len);
|
memcpy(payload, packed_ddt, packed_ddt_len);
|
||||||
unpacked_dt = ompi_datatype_create_from_packed_description(&payload,
|
unpacked_dt = ompi_datatype_create_from_packed_description(&payload,
|
||||||
ompi_proc_local());
|
ompi_proc_local());
|
||||||
free(ptr);
|
free(ptr);
|
||||||
if (unpacked_dt == MPI_INT32_T) {
|
if (unpacked_dt == MPI_INT32_T) {
|
||||||
printf("\tPASSED\n");
|
printf("\tPASSED\n");
|
||||||
@ -78,6 +85,62 @@ main(int argc, char* argv[])
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* TEST 2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
printf("---> Simple test using a struct and few predefined datatype (4 * MPI_INT).\n");
|
||||||
|
blen[0] = 1; blen[1] = 2; blen[2] = 3; blen[3] = 4;
|
||||||
|
disp[0] = 0; disp[1] = 4; disp[2] = 8; disp[3] = 12;
|
||||||
|
types[0] = MPI_INT; types[1] = MPI_INT; types[2] = MPI_INT; types[3] = MPI_INT;
|
||||||
|
ret = MPI_Type_create_struct( 4, blen, disp, types, &struct_type );
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
ret = MPI_Type_commit(&struct_type);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
ret = get_extents(struct_type, &old_lb, &old_extent, &old_true_lb, &old_true_extent);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
packed_ddt_len = ompi_datatype_pack_description_length(struct_type);
|
||||||
|
ptr = payload = malloc(packed_ddt_len);
|
||||||
|
ret = ompi_datatype_get_pack_description(struct_type, &packed_ddt);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
memcpy(payload, packed_ddt, packed_ddt_len);
|
||||||
|
|
||||||
|
ret = MPI_Type_free(&struct_type);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
unpacked_dt = ompi_datatype_create_from_packed_description(&payload, ompi_proc_local());
|
||||||
|
free(ptr);
|
||||||
|
if (unpacked_dt == NULL) {
|
||||||
|
printf("\tFAILED: could not unpack datatype\n");
|
||||||
|
ret = 1;
|
||||||
|
goto cleanup;
|
||||||
|
} else {
|
||||||
|
ret = get_extents(unpacked_dt, &lb, &extent, &true_lb, &true_extent);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
if (old_lb != lb || old_extent != extent ||
|
||||||
|
old_true_lb != true_lb || old_true_extent != extent) {
|
||||||
|
printf("\tFAILED: datatypes don't match\n");
|
||||||
|
ret = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
printf("\tPASSED\n");
|
||||||
|
}
|
||||||
|
ret = MPI_Type_free(&unpacked_dt);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* TEST 3
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
printf("---> Less Basic test with MPI_Type_vector\n");
|
printf("---> Less Basic test with MPI_Type_vector\n");
|
||||||
|
|
||||||
ret = MPI_Type_vector(2, 1, 1, MPI_INT, &vec_type);
|
ret = MPI_Type_vector(2, 1, 1, MPI_INT, &vec_type);
|
||||||
@ -93,6 +156,7 @@ main(int argc, char* argv[])
|
|||||||
ptr = payload = malloc(packed_ddt_len);
|
ptr = payload = malloc(packed_ddt_len);
|
||||||
ret = ompi_datatype_get_pack_description(vec_type, &packed_ddt);
|
ret = ompi_datatype_get_pack_description(vec_type, &packed_ddt);
|
||||||
if (ret != 0) goto cleanup;
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
memcpy(payload, packed_ddt, packed_ddt_len);
|
memcpy(payload, packed_ddt, packed_ddt_len);
|
||||||
ret = MPI_Type_free(&vec_type);
|
ret = MPI_Type_free(&vec_type);
|
||||||
if (ret != 0) goto cleanup;
|
if (ret != 0) goto cleanup;
|
||||||
@ -116,16 +180,75 @@ main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
printf("\tPASSED\n");
|
printf("\tPASSED\n");
|
||||||
}
|
}
|
||||||
|
ret = MPI_Type_free(&unpacked_dt);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* TEST 4
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
printf("---> Test with MPI_Type_create_indexed_block\n");
|
||||||
|
|
||||||
|
blen[0] = 0;
|
||||||
|
blen[1] = 20*sizeof(double);
|
||||||
|
|
||||||
|
ret = MPI_Type_create_indexed_block(2, 10, blen, MPI_DOUBLE, &newType);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
ret = MPI_Type_commit(&newType);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
ret = get_extents(newType, &old_lb, &old_extent, &old_true_lb, &old_true_extent);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
packed_ddt_len = ompi_datatype_pack_description_length(newType);
|
||||||
|
|
||||||
|
ptr = payload = malloc(packed_ddt_len);
|
||||||
|
ret = ompi_datatype_get_pack_description(newType, &packed_ddt);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
ret = MPI_Type_free(&newType);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
memcpy(payload, packed_ddt, packed_ddt_len);
|
||||||
|
unpacked_dt = ompi_datatype_create_from_packed_description(&payload,
|
||||||
|
ompi_proc_local());
|
||||||
|
free(ptr);
|
||||||
|
if (unpacked_dt == NULL) {
|
||||||
|
printf("\tFAILED: could not unpack datatype\n");
|
||||||
|
ret = 1;
|
||||||
|
goto cleanup;
|
||||||
|
} else {
|
||||||
|
ret = get_extents(unpacked_dt, &lb, &extent, &true_lb, &true_extent);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
if (old_lb != lb || old_extent != extent ||
|
||||||
|
old_true_lb != true_lb || old_true_extent != extent) {
|
||||||
|
printf("\tFAILED: datatypes don't match\n");
|
||||||
|
ret = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
printf("\tPASSED\n");
|
||||||
|
}
|
||||||
|
ret = MPI_Type_free(&unpacked_dt);
|
||||||
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* TEST 5
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
printf("---> Advanced test with hindexed\n");
|
printf("---> Advanced test with hindexed\n");
|
||||||
|
|
||||||
blen[0] = 10;
|
blen[0] = 10;
|
||||||
blen[1] = 10;
|
blen[1] = 10;
|
||||||
disp[0] = 0;
|
disp[0] = 0;
|
||||||
disp[1] = 20*sizeof(double);
|
disp[1] = 20*sizeof(double);
|
||||||
|
|
||||||
ret = MPI_Type_create_hindexed(2, blen, disp, MPI_DOUBLE,
|
ret = MPI_Type_create_hindexed(2, blen, disp, MPI_DOUBLE, &newType);
|
||||||
&newType);
|
|
||||||
if (ret != 0) goto cleanup;
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
ret = MPI_Type_commit(&newType);
|
ret = MPI_Type_commit(&newType);
|
||||||
@ -159,6 +282,12 @@ main(int argc, char* argv[])
|
|||||||
printf("\tPASSED\n");
|
printf("\tPASSED\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* TEST 6
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
printf("---> Even more advanced test using the previous type and struct\n");
|
printf("---> Even more advanced test using the previous type and struct\n");
|
||||||
blen[0] = 11;
|
blen[0] = 11;
|
||||||
blen[1] = 2;
|
blen[1] = 2;
|
||||||
@ -166,7 +295,7 @@ main(int argc, char* argv[])
|
|||||||
disp[1] = 64;
|
disp[1] = 64;
|
||||||
types[0] = MPI_INT;
|
types[0] = MPI_INT;
|
||||||
types[1] = newType;
|
types[1] = newType;
|
||||||
MPI_Type_create_struct( 2, blen, disp, types, &struct_type );
|
ret = MPI_Type_create_struct( 2, blen, disp, types, &struct_type );
|
||||||
if (ret != 0) goto cleanup;
|
if (ret != 0) goto cleanup;
|
||||||
|
|
||||||
ret = MPI_Type_commit(&struct_type);
|
ret = MPI_Type_commit(&struct_type);
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user