cvar_write.c 4.42 KB
Newer Older
1
2
3
4
5
6
7
8
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
 *  (C) 2011 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

#include "mpiimpl.h"

9
/* -- Begin Profiling Symbol Block for routine MPI_T_cvar_write */
10
#if defined(HAVE_PRAGMA_WEAK)
11
#pragma weak MPI_T_cvar_write = PMPI_T_cvar_write
12
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
13
#pragma _HP_SECONDARY_DEF PMPI_T_cvar_write  MPI_T_cvar_write
14
#elif defined(HAVE_PRAGMA_CRI_DUP)
15
#pragma _CRI duplicate MPI_T_cvar_write as PMPI_T_cvar_write
16
#elif defined(HAVE_WEAK_ATTRIBUTE)
17
int MPI_T_cvar_write(MPI_T_cvar_handle handle, const void *buf) __attribute__((weak,alias("PMPI_T_cvar_write")));
18
19
20
21
22
23
#endif
/* -- End Profiling Symbol Block */

/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
   the MPI routines */
#ifndef MPICH_MPI_FROM_PMPI
24
25
#undef MPI_T_cvar_write
#define MPI_T_cvar_write PMPI_T_cvar_write
26
27
28
29
30
31
32

/* any non-MPI functions go here, especially non-static ones */

#undef FUNCNAME
#define FUNCNAME MPIR_T_cvar_write_impl
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
33
int MPIR_T_cvar_write_impl(MPI_T_cvar_handle handle, const void *buf)
34
35
{
    int mpi_errno = MPI_SUCCESS;
36
37
38
39
40
41
42
43
44
45
    int i, count;
    void *addr;
    MPIR_T_cvar_handle_t *hnd = handle;

    if (hnd->scope == MPI_T_SCOPE_CONSTANT) {
        mpi_errno = MPI_T_ERR_CVAR_SET_NEVER;
        goto fn_fail;
    } else if (hnd->scope == MPI_T_SCOPE_READONLY) {
        mpi_errno = MPI_T_ERR_CVAR_SET_NOT_NOW;
        goto fn_fail;
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
    count = hnd->count;
    addr = hnd->addr;
    MPIU_Assert(addr != NULL);

    switch (hnd->datatype) {
    case MPI_INT:
        for (i = 0; i < count; i++)
            ((int *)addr)[i] = ((int *)buf)[i];
        break;
    case MPI_UNSIGNED:
        for (i = 0; i < count; i++)
            ((unsigned *)addr)[i] = ((unsigned *)buf)[i];
        break;
    case MPI_UNSIGNED_LONG:
        for (i = 0; i < count; i++)
            ((unsigned long *)addr)[i] = ((unsigned long *)buf)[i];
        break;
    case MPI_UNSIGNED_LONG_LONG:
        for (i = 0; i < count; i++)
            ((unsigned long long *)addr)[i] = ((unsigned long long *)buf)[i];
        break;
    case MPI_DOUBLE:
        for (i = 0; i < count; i++)
            ((double *)addr)[i] = ((double *)buf)[i];
        break;
    case MPI_CHAR:
74
        MPIU_Assert(count > strlen(buf)); /* Make sure buf will not overflow this cvar */
75
76
77
78
79
80
81
        MPIU_Strncpy(addr, buf, count);
        break;
    default:
         /* FIXME the error handling code may not have been setup yet */
        MPIU_ERR_SETANDJUMP1(mpi_errno, MPI_ERR_INTERN, "**intern", "**intern %s", "unexpected parameter type");
        break;
    }
82
83
84
85
86
87
88
89
90
91

fn_exit:
    return mpi_errno;
fn_fail:
    goto fn_exit;
}

#endif /* MPICH_MPI_FROM_PMPI */

#undef FUNCNAME
92
#define FUNCNAME MPI_T_cvar_write
93
94
95
#undef FCNAME
#define FCNAME MPIU_QUOTE(FUNCNAME)
/*@
96
MPI_T_cvar_write - Write a control variable
97
98
99
100
101
102
103
104

Input Parameters:
+ handle - handle of the control variable to be written (handle)
- buf - initial address of storage location for variable value (choice)

.N ThreadSafe

.N Errors
105
106
107
108
109
.N MPI_SUCCESS
.N MPI_T_ERR_NOT_INITIALIZED
.N MPI_T_ERR_INVALID_HANDLE
.N MPI_T_ERR_CVAR_SET_NOT_NOW
.N MPI_T_ERR_CVAR_SET_NEVER
110
@*/
111
int MPI_T_cvar_write(MPI_T_cvar_handle handle, const void *buf)
112
113
114
{
    int mpi_errno = MPI_SUCCESS;

115
    MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CVAR_WRITE);
Junchao Zhang's avatar
Junchao Zhang committed
116
    MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
117
    MPIR_T_THREAD_CS_ENTER();
118
    MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CVAR_WRITE);
119

120
   /* Validate parameters */
121
122
123
124
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS
        {
Junchao Zhang's avatar
Junchao Zhang committed
125
            MPIR_ERRTEST_CVAR_HANDLE(handle, mpi_errno);
126
            MPIR_ERRTEST_ARGNULL(buf, "buf", mpi_errno);
127
128
129
130
131
132
133
134
135
136
137
138
139
        }
        MPID_END_ERROR_CHECKS
    }
#   endif /* HAVE_ERROR_CHECKING */

    /* ... body of routine ...  */

    mpi_errno = MPIR_T_cvar_write_impl(handle, buf);
    if (mpi_errno) MPIU_ERR_POP(mpi_errno);

    /* ... end of body of routine ... */

fn_exit:
140
    MPID_MPI_FUNC_EXIT(MPID_STATE_MPI_T_CVAR_WRITE);
141
    MPIR_T_THREAD_CS_EXIT();
142
143
144
145
146
147
148
149
    return mpi_errno;

fn_fail:
    /* --BEGIN ERROR HANDLING-- */
#   ifdef HAVE_ERROR_CHECKING
    {
        mpi_errno = MPIR_Err_create_code(
            mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER,
150
            "**mpi_t_cvar_write", "**mpi_t_cvar_write %p %p", handle, buf);
151
152
153
154
155
156
    }
#   endif
    mpi_errno = MPIR_Err_return_comm(NULL, FCNAME, mpi_errno);
    goto fn_exit;
    /* --END ERROR HANDLING-- */
}