Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

msmpot.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 2008-2009 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: msmpot.c,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.3 $      $Date: 2010/06/03 20:07:08 $
00015  *
00016  ***************************************************************************/
00017 
00018 #include "msmpot_internal.h"
00019 
00020 #undef  NELEMS
00021 #define NELEMS(a)  ((int)(sizeof(a)/sizeof(a[0])))
00022 
00023 
00024 /* these strings correspond to the return codes in msmpot.h,
00025  * where the "unknown error" is used for out-of-range retcode */
00026 static const char *ERROR_STRING[] = {
00027   "success",
00028   "assertion failed",
00029   "memory allocation error",
00030   "illegal parameter",
00031   "unsupported request",
00032   "CUDA device request failed",
00033   "CUDA memory allocation error",
00034   "CUDA memory copy error",
00035   "CUDA kernel execution failed",
00036   "CUDA kernel does not support request",
00037   "unknown error",
00038 };
00039 
00040 /* assume that the "unknown" error is listed last */
00041 const char *Msmpot_error_string(int retcode) {
00042   if (retcode < 0 || retcode >= NELEMS(ERROR_STRING)) {
00043     retcode = NELEMS(ERROR_STRING) - 1;
00044   }
00045   return ERROR_STRING[retcode];
00046 }
00047 
00048 
00049 #ifdef MSMPOT_DEBUG
00050 
00051 /* When debugging report error to stderr stream, return "err".
00052  * Note that we can't use Msmpot_error_message() since 
00053  * we might not have the Msmpot * available to us. */
00054 int Msmpot_report_error(int err, const char *msg, const char *fn, int ln) {
00055   if (msg) {
00056     fprintf(stderr, "MSMPOT ERROR (%s,%d): %s: %s\n",
00057         fn, ln, Msmpot_error_string(err), msg);
00058   }
00059   else {
00060     fprintf(stderr, "MSMPOT ERROR (%s,%d): %s\n",
00061         fn, ln, Msmpot_error_string(err));
00062   }
00063   return err;
00064 }
00065 
00066 #endif
00067 
00068 
00069 Msmpot *Msmpot_create(void) {
00070   Msmpot *msm = (Msmpot *) calloc(1, sizeof(Msmpot));
00071   if (NULL == msm) return NULL;
00072 #ifdef MSMPOT_CUDA
00073   msm->msmcuda = Msmpot_cuda_create();
00074   if (NULL == msm->msmcuda) {
00075     Msmpot_destroy(msm);
00076     return NULL;
00077   }
00078 #endif
00079   Msmpot_set_defaults(msm);
00080   return msm;
00081 }
00082 
00083 
00084 void Msmpot_destroy(Msmpot *msm) {
00085 #ifdef MSMPOT_CUDA
00086   if (msm->msmcuda) Msmpot_cuda_destroy(msm->msmcuda);
00087 #endif
00088   Msmpot_cleanup(msm);
00089   free(msm);
00090 }
00091 
00092 
00093 int Msmpot_use_cuda(Msmpot *msm, const int *devlist, int listlen,
00094     int cuda_optional) {
00095   if (NULL == devlist || listlen <= 0) {
00096     return ERROR(MSMPOT_ERROR_PARAM);
00097   }
00098 #ifdef MSMPOT_CUDA
00099   msm->devlist = devlist;
00100   msm->devlistlen = listlen;
00101   msm->cuda_optional = cuda_optional;
00102   msm->use_cuda = 1;  /* attempt to use CUDA */
00103   return MSMPOT_SUCCESS;
00104 #else
00105   return ERRMSG(MSMPOT_ERROR_SUPPORT,
00106       "CUDA support is not available in this build");
00107 #endif
00108 }

Generated on Fri Apr 19 02:44:42 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002