1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ 2 /* 3 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana 4 * University Research and Technology 5 * Corporation. All rights reserved. 6 * Copyright (c) 2004-2005 The University of Tennessee and The University 7 * of Tennessee Research Foundation. All rights 8 * reserved. 9 * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart, 10 * University of Stuttgart. All rights reserved. 11 * Copyright (c) 2004-2005 The Regents of the University of California. 12 * All rights reserved. 13 * Copyright (c) 2010-2012 Cisco Systems, Inc. All rights reserved. 14 * Copyright (c) 2013 Los Alamos National Security, LLC. All rights 15 * reserved. 16 * Copyright (c) 2015 Research Organization for Information Science 17 * and Technology (RIST). All rights reserved. 18 * $COPYRIGHT$ 19 * 20 * Additional copyrights may follow 21 * 22 * $HEADER$ 23 */ 24 #include "ompi_config.h" 25 #include <stdio.h> 26 27 #include "ompi/mpi/c/bindings.h" 28 #include "ompi/runtime/params.h" 29 #include "ompi/communicator/communicator.h" 30 #include "ompi/errhandler/errhandler.h" 31 #include "ompi/mpi/fortran/base/fint_2_int.h" 32 #include "ompi/mpi/fortran/base/constants.h" 33 #include "ompi/memchecker.h" 34 35 #if OMPI_BUILD_MPI_PROFILING 36 #if OPAL_HAVE_WEAK_SYMBOLS 37 #pragma weak MPI_Status_c2f = PMPI_Status_c2f 38 #endif 39 #define MPI_Status_c2f PMPI_Status_c2f 40 #endif 41 42 static const char FUNC_NAME[] = "MPI_Status_c2f"; 43 44 45 int MPI_Status_c2f(const MPI_Status *c_status, MPI_Fint *f_status) 46 { 47 const int *c_ints; 48 int i; 49 MEMCHECKER( 50 if(c_status != MPI_STATUSES_IGNORE) { 51 /* 52 * Before checking the complete status, we need to reset the definedness 53 * of the MPI_ERROR-field (single-completion calls wait/test). 54 */ 55 opal_memchecker_base_mem_defined((void*)&c_status->MPI_ERROR, sizeof(int)); 56 memchecker_status(c_status); 57 } 58 ); 59 60 OPAL_CR_NOOP_PROGRESS(); 61 62 if (MPI_PARAM_CHECK) { 63 OMPI_ERR_INIT_FINALIZE(FUNC_NAME); 64 65 /* MPI-2:4.12.5 says that if you pass in 66 MPI_STATUS[ES]_IGNORE, it's erroneous */ 67 68 if (NULL == c_status || MPI_STATUS_IGNORE == c_status || 69 MPI_STATUSES_IGNORE == c_status || NULL == f_status) { 70 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, 71 MPI_ERR_IN_STATUS, FUNC_NAME); 72 } 73 } 74 75 /* Note that MPI-2.2 16.3.5 states that even the hidden data in a 76 status must be converted (!). This is somewhat problematic 77 because the Fortran data is all INTEGERS while the C MPI_Status 78 contains a size_t. That being said, note 2 things: 79 80 1. The _ucount and _canceled members are never accessed from 81 Fortran. 82 2. configure calculated a value of MPI_STATUS_SIZE to ensure 83 that the Fortran status is the Right size to hold the C 84 MPI_Status (including the size_t member). 85 86 So for the purposes of this function, just copy over all the 87 data as if they were int's. This works because all OMPI 88 Fortran MPI API functions that take a status as an IN argument 89 first call MPI_Status_f2c on it before using it (in which case 90 we'll do the exact opposite copy, thereby rebuilding the size_t 91 value properly before it is accessed in C). 92 93 Note that if sizeof(int) > sizeof(INTEGER), we're potentially 94 hosed anyway (i.e., even the public values in the status could 95 get truncated). But if sizeof(int) == sizeof(INTEGER) or 96 sizeof(int) < sizeof(INTEGER), everything should be kosher. */ 97 c_ints = (const int*)c_status; 98 for( i = 0; i < (int)(sizeof(MPI_Status) / sizeof(int)); i++ ) 99 f_status[i] = OMPI_INT_2_FINT(c_ints[i]); 100 101 return MPI_SUCCESS; 102 }