File: tgetconts.c

package info (click to toggle)
lam 7.1.2-1.4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 54,608 kB
  • ctags: 17,034
  • sloc: ansic: 156,264; sh: 9,976; cpp: 7,699; makefile: 5,589; perl: 476; fortran: 260; asm: 83
file content (176 lines) | stat: -rw-r--r-- 4,353 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
 * Copyright (c) 2001-2002 The Trustees of Indiana University.  
 *                         All rights reserved.
 * Copyright (c) 1998-2001 University of Notre Dame. 
 *                         All rights reserved.
 * Copyright (c) 1994-1998 The Ohio State University.  
 *                         All rights reserved.
 * 
 * This file is part of the LAM/MPI software package.  For license
 * information, see the LICENSE file in the top level directory of the
 * LAM/MPI source distribution.
 * 
 * $HEADER$
 *
 * $Id: tgetconts.c,v 1.5 2002/12/16 16:23:31 jsquyres Exp $
 *
 *	Function:	- get datatype contents
 *	Accepts:	- MPI datatype
 *			- number of integers
 *			- number of addresses
 *			- number of datatypes
 *			- array of integers (out)
 *			- array of addresses (out)
 *			- array of datatypes (out)
 *	Returns:	- MPI_SUCCESS or error code
 */

#include <string.h>

#include <blktype.h>
#include <mpi.h>
#include <mpisys.h>

/*@
   MPI_Type_get_contents - Get datatype contents

Input Parameter:
+ type - Datatype to access
. nints - Number of elements in ints
. naddrs - Number of elments in addrs
- ndtypes - Number of elements in dtypes

Output Parameters:
+ ints - Contains integer arguments used in constructing datatype 
. addrs - Contains address arguments used in constructing datatype
- dtypes - Contains datatype arguments used in constructing datatype

.N fortran

.N Errors
.N MPI_SUCCESS
.N MPI_ERR_ARG
.N MPI_ERR_TYPE

.seealso MPI_Type_get_envelope(3)

.N WEB
@*/

int
MPI_Type_get_contents(MPI_Datatype type, int nints, int naddrs, 
		      int ndtypes, int *ints, MPI_Aint *addrs, 
		      MPI_Datatype *dtypes)
{
	int		i;

	lam_initerr_m();
	lam_setfunc_m(BLKMPITGETCONT);
/*
 * Check arguments.
 */
	if (type == MPI_DATATYPE_NULL) {
		return(lam_errfunc(MPI_COMM_WORLD, BLKMPITGETCONT,
					lam_mkerr(MPI_ERR_TYPE, EINVAL)));
	}

	if (dtypes == 0) {
		return(lam_errfunc(MPI_COMM_WORLD, BLKMPITGETCONT,
					lam_mkerr(MPI_ERR_ARG, EINVAL)));
	}

	if (type->dt_flags & LAM_DTISDUP) {
	    dtypes[0] = (MPI_Datatype) type->dt_uargs;
	    dtypes[0]->dt_refcount++;
	}
	else if (type->dt_flags & LAM_DTISRESIZE) {
	    dtypes[0] = (MPI_Datatype) type->dt_uargs;
	    addrs[0] = type->dt_lower;
	    addrs[1] = type->dt_upper - type->dt_lower;
	    dtypes[0]->dt_refcount++;
	}
	else {
	    switch (type->dt_format) {

	    case LAM_DTBASIC:
		return(lam_errfunc(MPI_COMM_WORLD, BLKMPITGETCONT,
		    			lam_mkerr(MPI_ERR_TYPE, EINVAL)));

	    case LAM_DTCONTIG:
		dtypes[0] = type->dt_dtype;
		ints[0] = type->dt_count;
		dtypes[0]->dt_refcount++;
		break;

	    case LAM_DTSTRUCT:
	    case LAM_DTSTRUCTCREAT:
		ints[0] = type->dt_count;
		for (i = 0; i < ints[0]; i++) {
		    ints[i + 1] = type->dt_lengths[i];
		    addrs[i] = type->dt_disps[i];
		    dtypes[i] = type->dt_dtypes[i];
		    dtypes[i]->dt_refcount++;
		}
		break;

	    case LAM_DTINDEXED:
		dtypes[0] = type->dt_dtype;
		dtypes[0]->dt_refcount++;
		ints[0] = type->dt_count;
		for (i = 0; i < ints[0]; i++) {
		    ints[i + 1] = type->dt_lengths[i];
		    ints[ints[0] + 1 + i] = (int) type->dt_disps[i];
		}
		break;

	    case LAM_DTHINDEXED:
	    case LAM_DTHINDEXEDCREAT:
		dtypes[0] = type->dt_dtype;
		ints[0] = type->dt_count;
		for (i = 0; i < ints[0]; i++) {
		    ints[i + 1] = type->dt_lengths[i];
		    addrs[i] = type->dt_disps[i];
		}
		break;

	    case LAM_DTVECTOR:
		dtypes[0] = type->dt_dtype;
		dtypes[0]->dt_refcount++;
		ints[0] = type->dt_count;
		ints[1] = type->dt_length;
		ints[2] = type->dt_stride;
		break;

	    case LAM_DTHVECTOR:
	    case LAM_DTHVECTORCREAT:
		dtypes[0] = type->dt_dtype;
		dtypes[0]->dt_refcount++;
		ints[0] = type->dt_count;
		ints[1] = type->dt_length;
		addrs[0] = type->dt_stride;
		break;

	    case LAM_DTSUBARRAY:
		dtypes[0] = type->dt_dtype;
		dtypes[0]->dt_refcount++;
		lam_memcpy((char *) ints, (char *) type->dt_uargs, 
			   (3 * type->dt_uargs[0] + 2) * sizeof(int));
		break;

	    case LAM_DTDARRAY:
		dtypes[0] = type->dt_dtype;
		dtypes[0]->dt_refcount++;
		lam_memcpy((char *) ints, (char *) type->dt_uargs, 
			   (4 * type->dt_uargs[2] + 4) * sizeof(int));
		break;

	    case LAM_DTINDEXEDBLK:
	    default:
		return(lam_errfunc(MPI_COMM_WORLD, BLKMPITGETCONT,
		    			lam_mkerr(MPI_ERR_TYPE, EINVAL)));
	    }
	}

	lam_resetfunc_m(BLKMPITGETCONT);
	return(MPI_SUCCESS);
}