找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1158|回复: 0
打印 上一主题 下一主题
收起左侧

MATLAB矩阵相乘源程序

[复制链接]
跳转到指定楼层
楼主
matlab 矩阵相乘


全部资料51hei下载地址:
mtimesx_20110223.zip (255.8 KB, 下载次数: 7)
  1. /* OpenMP ------------------------------------------------------------- */

  2. #ifdef _OPENMP
  3. #include <omp.h>
  4. #endif

  5. /* Includes ----------------------------------------------------------- */

  6. #include <string.h>
  7. #include <stddef.h>
  8. #include <ctype.h>
  9. #include <math.h>
  10. #include <time.h>
  11. #include "mex.h"

  12. /* Macros ------------------------------------------------------------- */

  13. #ifndef MWSIZE_MAX
  14. #define  mwIndex        int
  15. #define  mwSignedIndex  int
  16. #define  mwSize         int
  17. #define  mwSize_t       size_t
  18. #else
  19. #define  mwSize_t       mwSize
  20. #endif

  21. #define  METHOD_BLAS       0
  22. #define  METHOD_LOOPS      1
  23. #define  METHOD_LOOPS_OMP  2

  24. #define  MTIMESX_NOT_SET    0
  25. #define  MTIMESX_BLAS       1
  26. #define  MTIMESX_LOOPS      2
  27. #define  MTIMESX_LOOPS_OMP  3
  28. #define  MTIMESX_MATLAB     4
  29. #define  MTIMESX_SPEED      5
  30. #define  MTIMESX_SPEED_OMP  6

  31. #define  STRINGIZE(name)  #name
  32. #define  TOKENSTRING(name)  STRINGIZE(name)

  33. #define  DIRECTIVE_MAX  1000

  34. #ifndef  COMPILER
  35. #define  COMPILER  (unknown)
  36. #endif

  37. /* Prototypes --------------------------------------------------------- */

  38. mxArray *DoubleTimesDouble(mxArray *, char, mxArray *, char);
  39. mxArray *FloatTimesFloat(mxArray *, char, mxArray *, char);
  40. mxArray *mxCreateSharedDataCopy(const mxArray *pr);
  41. char mxArrayToTrans(const mxArray *mx);
  42. void *myRealloc(void *vp, mwSize_t n);
  43. void mtimesx_logo(void);
  44. mxArray *modestring(int);

  45. /* Global Variables --------------------------------------------------- */

  46. int mtimesx_mode  = MTIMESX_MATLAB;
  47. int max_threads   = 0;
  48. int threads_used  = 0;
  49. int debug         = 0;
  50. int debug_message = 0;

  51. /* Functions ect for OpenMP implementations ------- */

  52. #ifdef _OPENMP

  53. #define  OPENMP_ENABLED   1.0

  54. /* Functions etc for non OpenMP implementations ----------------- */

  55. /* The omp_get_num_procs() function is courtesy of Dirk-Jan Kroon */
  56. /* and is based on his FEX submission maxNumCompThreads --------- */

  57. #else

  58. #define  OPENMP_ENABLED   0.0
  59. #define  omp_get_wtick()  0.0
  60. #define  omp_get_wtime()  ((double)clock()/((double)CLOCKS_PER_SEC))

  61. #if defined(_WIN32) || defined(_WIN64)

  62. #include <windows.h>
  63. int omp_get_num_procs( ) {
  64.     SYSTEM_INFO sysinfo;
  65.     GetSystemInfo(&sysinfo);
  66.     return sysinfo.dwNumberOfProcessors;
  67. }

  68. #elif MACOS

  69. #include <sys/param.h>
  70. #include <sys/sysctl.h>
  71. int omp_get_num_procs( ) {
  72.     int nm[2];
  73.     size_t len = 4;
  74.     uint32_t count;

  75.     nm[0] = CTL_HW; nm[1] = HW_AVAILCPU;
  76.     sysctl(nm, 2, &count, &len, NULL, 0);

  77.     if(count < 1) {
  78.         nm[1] = HW_NCPU;
  79.         sysctl(nm, 2, &count, &len, NULL, 0);
  80.         if(count < 1) { count = 1; }
  81.     }
  82.     return count;
  83. }
  84. #else

  85. #include <unistd.h>
  86. int omp_get_num_procs( ) {
  87.     return sysconf(_SC_NPROCESSORS_ONLN);
  88. }

  89. #endif

  90. #endif

  91. /*------------------------------------------------------------------------ */
  92. /*------------------------------------------------------------------------ */
  93. /*------------------------------------------------------------------------ */
  94. /*------------------------------------------------------------------------ */

  95. void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])
  96. {
  97.     mxArray *A, *B, *C, *Araw, *Braw;
  98.     mxArray *rhs[4];
  99.     char transa, transb;
  100.     char *directive, *cp;
  101.     char transstring[2] = "_";
  102.     int unsupported = 0;
  103.     int i, j, k, got_directive, nrhs_old = nrhs;
  104.         int mtimesx_mode_new, max_threads_new,
  105.                 already_set_mode, already_set_debug, already_set_threads;
  106.         mxArray *ans;
  107.         double threads;

  108. /*-------------------------------------------------------------------------
  109. * Check for proper number of inputs and outputs
  110. *------------------------------------------------------------------------- */

  111.     if( nlhs > 1 ) {
  112.         mexErrMsgTxt("Must have at most 1 output.");
  113.     }

  114. /*-------------------------------------------------------------------------
  115. * If no inputs, just return the current mode
  116. *------------------------------------------------------------------------- */

  117.     if( nrhs == 0 ) {
  118.                 plhs[0] = modestring(mtimesx_mode);
  119.         return;
  120.     }

  121. /*-------------------------------------------------------------------------
  122. * Find out if any input is a directive
  123. *------------------------------------------------------------------------- */

  124.         i = 0;
  125.         mtimesx_mode_new    = MTIMESX_NOT_SET;
  126.         max_threads_new     = 0;
  127.         already_set_mode    = 0;
  128.         already_set_debug   = 0;
  129.         already_set_threads = 0;
  130.         while( i < nrhs ) {
  131.         if( mxIsChar(prhs[i]) ) {
  132.                 if( mxGetNumberOfElements(prhs[i]) > DIRECTIVE_MAX ) {
  133. ……………………

  134. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表