[5725] | 1 | /* |
---|
| 2 | * copy.c |
---|
| 3 | * |
---|
| 4 | * memcpy "wrapper" to copy MPI Datatypes |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "mpiP.h" |
---|
| 9 | #include "type.h" |
---|
| 10 | #include <string.h> |
---|
| 11 | #include <stdio.h> |
---|
| 12 | #include <stdlib.h> |
---|
| 13 | #include <limits.h> |
---|
| 14 | |
---|
| 15 | //For type matching |
---|
| 16 | #ifdef HAVE_CONFIG_H |
---|
| 17 | #include <config.h> |
---|
| 18 | #endif |
---|
| 19 | |
---|
| 20 | /* |
---|
| 21 | * rml: this prototype should be in mpiP.h, but mpiP.h does not currently |
---|
| 22 | * include type.h so it can't just be added right now. Come back and |
---|
| 23 | * fix this issue later... |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | extern int Pcopy_data2(void *source, int src_count, Datatype src_type, |
---|
| 27 | void *dest, int dest_count, Datatype dest_type); |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | int copy_data2(void *source, int src_count, MPI_Datatype src_type, |
---|
| 31 | void *dest, int dest_count, MPI_Datatype dest_type) |
---|
| 32 | { |
---|
| 33 | Datatype src_ptr = *(Datatype*) mpi_handle_to_datatype(src_type); |
---|
| 34 | Datatype dest_ptr = *(Datatype*) mpi_handle_to_datatype(dest_type); |
---|
| 35 | |
---|
| 36 | return Pcopy_data2(source, src_count, src_ptr, dest, dest_count, dest_ptr); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | int Pcopy_data2(void *source, int src_count, Datatype src_type, |
---|
| 43 | void *dest, int dest_count, Datatype dest_type) |
---|
| 44 | { |
---|
| 45 | int i; |
---|
| 46 | int soffset, doffset; |
---|
| 47 | MPI_Aint src_extent, dest_extent; |
---|
| 48 | |
---|
| 49 | //commit checking here, since if any datatype is used in this function |
---|
| 50 | // it is considered "communication". Should it be somewhere else? |
---|
| 51 | |
---|
| 52 | if (!(src_type->committed && dest_type->committed)) |
---|
| 53 | { |
---|
| 54 | fprintf(stderr, "Type not committed\n"); |
---|
| 55 | exit(-1); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | // A receive of less elements than sent |
---|
| 59 | // is valid, but the reverse is a violation |
---|
| 60 | |
---|
| 61 | if (src_type->count * src_count < dest_type->count * dest_count) |
---|
| 62 | { |
---|
| 63 | printf("copy_data: Trying to over-receive\n"); |
---|
| 64 | exit(1); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | Type_extent(src_type, &src_extent); |
---|
| 68 | Type_extent(dest_type, &dest_extent); |
---|
| 69 | |
---|
| 70 | for (i = 0; i < dest_count * dest_type->count; i++) |
---|
| 71 | { |
---|
| 72 | |
---|
| 73 | #ifdef TYPE_CHECKING |
---|
| 74 | if ( src_type->pairs[i % src_type->count].type != |
---|
| 75 | dest_type->pairs[i % dest_type->count].type) |
---|
| 76 | { |
---|
| 77 | printf("copy_data: Types don't match.\n"); |
---|
| 78 | exit(1); |
---|
| 79 | } |
---|
| 80 | #endif |
---|
| 81 | |
---|
| 82 | soffset = src_type->pairs[i % src_type->count].disp + ((i / src_type->count) * src_extent); |
---|
| 83 | doffset = dest_type->pairs[i % dest_type->count].disp + ((i / dest_type->count) * dest_extent); |
---|
| 84 | |
---|
| 85 | memcpy(dest+doffset, source+soffset, Simpletype_length(dest_type->pairs[i % dest_type->count].type)); |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | |
---|