add pack / unpack test
This commit was SVN r14801.
Этот коммит содержится в:
родитель
84f7ed70b3
Коммит
f02a9525dc
@ -10,7 +10,7 @@
|
||||
# $HEADER$
|
||||
#
|
||||
|
||||
TESTS = ddt_test checksum position
|
||||
TESTS = ddt_test checksum position ddt_pack
|
||||
|
||||
check_PROGRAMS = $(TESTS) to_self
|
||||
|
||||
@ -18,6 +18,10 @@ ddt_test_SOURCES = ddt_test.c
|
||||
ddt_test_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS)
|
||||
ddt_test_LDADD = $(top_builddir)/ompi/libmpi.la
|
||||
|
||||
ddt_pack_SOURCES = ddt_pack.c
|
||||
ddt_pack_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS)
|
||||
ddt_pack_LDADD = $(top_builddir)/ompi/libmpi.la
|
||||
|
||||
checksum_SOURCES = checksum.c
|
||||
checksum_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS)
|
||||
checksum_LDADD = $(top_builddir)/ompi/libmpi.la
|
||||
|
97
test/datatype/ddt_pack.c
Обычный файл
97
test/datatype/ddt_pack.c
Обычный файл
@ -0,0 +1,97 @@
|
||||
/* -*- Mode: C; c-basic-offset:4 ; -*- */
|
||||
/*
|
||||
* Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
|
||||
* University Research and Technology
|
||||
* Corporation. All rights reserved.
|
||||
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
||||
* of Tennessee Research Foundation. All rights
|
||||
* reserved.
|
||||
* Copyright (c) 2004-2006 High Performance Computing Center Stuttgart,
|
||||
* University of Stuttgart. All rights reserved.
|
||||
* Copyright (c) 2004-2006 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2006 Sun Microsystems Inc. All rights reserved.
|
||||
* $COPYRIGHT$
|
||||
*
|
||||
* Additional copyrights may follow
|
||||
*
|
||||
* $HEADER$
|
||||
*/
|
||||
|
||||
#include "ompi_config.h"
|
||||
#include "ompi/datatype/datatype.h"
|
||||
#include "ompi/datatype/datatype_internal.h"
|
||||
#include "ompi/datatype/convertor.h"
|
||||
#include "ompi/proc/proc.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
size_t packed_ddt_len;
|
||||
const void *packed_ddt;
|
||||
void *payload, *ptr;
|
||||
struct ompi_datatype_t *unpacked_dt;
|
||||
int ret = 0;
|
||||
int blen[2];
|
||||
MPI_Aint disp[2];
|
||||
MPI_Datatype newType;
|
||||
|
||||
MPI_Init(&argc, &argv);
|
||||
|
||||
/* Basic test... */
|
||||
printf("---> Basic test with MPI_INT\n");
|
||||
|
||||
packed_ddt_len = ompi_ddt_pack_description_length(MPI_INT);
|
||||
ptr = payload = malloc(packed_ddt_len);
|
||||
ret = ompi_ddt_get_pack_description(MPI_INT, &packed_ddt);
|
||||
if (ret != 0) goto cleanup;
|
||||
memcpy(payload, packed_ddt, packed_ddt_len);
|
||||
unpacked_dt = ompi_ddt_create_from_packed_description(&payload,
|
||||
ompi_proc_local());
|
||||
free(ptr);
|
||||
if (unpacked_dt == MPI_INT) {
|
||||
printf("\tPASSED\n");
|
||||
} else {
|
||||
printf("\tFAILED: datatypes don't match\n");
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
printf("---> Advanced test with hindexed\n");
|
||||
|
||||
blen[0] = 10;
|
||||
blen[1] = 10;
|
||||
disp[0] = 0;
|
||||
disp[1] = 20*sizeof(double);
|
||||
|
||||
ret = MPI_Type_create_hindexed(2, blen, disp, MPI_DOUBLE,
|
||||
&newType);
|
||||
if (ret != 0) goto cleanup;
|
||||
|
||||
ret = MPI_Type_commit(&newType);
|
||||
if (ret != 0) goto cleanup;
|
||||
|
||||
packed_ddt_len = ompi_ddt_pack_description_length(newType);
|
||||
ptr = payload = malloc(packed_ddt_len);
|
||||
ret = ompi_ddt_get_pack_description(newType, &packed_ddt);
|
||||
if (ret != 0) goto cleanup;
|
||||
memcpy(payload, packed_ddt, packed_ddt_len);
|
||||
unpacked_dt = ompi_ddt_create_from_packed_description(&payload,
|
||||
ompi_proc_local());
|
||||
free(ptr);
|
||||
if (unpacked_dt != NULL) {
|
||||
printf("\tPASSED\n");
|
||||
} else {
|
||||
printf("\tFAILED: datatypes don't match\n");
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
MPI_Finalize();
|
||||
|
||||
return ret;
|
||||
}
|
Загрузка…
x
Ссылка в новой задаче
Block a user