标题:
MATLAB矩阵相乘源程序
[打印本页]
作者:
lynzdh
时间:
2019-1-12 10:43
标题:
MATLAB矩阵相乘源程序
matlab 矩阵相乘
0.png
(11.52 KB, 下载次数: 14)
下载附件
2019-1-12 18:17 上传
全部资料51hei下载地址:
mtimesx_20110223.zip
(255.8 KB, 下载次数: 7)
2019-1-12 10:42 上传
点击文件名下载附件
matlab 矩阵
下载积分: 黑币 -5
/* OpenMP ------------------------------------------------------------- */
#ifdef _OPENMP
#include <omp.h>
#endif
/* Includes ----------------------------------------------------------- */
#include <string.h>
#include <stddef.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include "mex.h"
/* Macros ------------------------------------------------------------- */
#ifndef MWSIZE_MAX
#define mwIndex int
#define mwSignedIndex int
#define mwSize int
#define mwSize_t size_t
#else
#define mwSize_t mwSize
#endif
#define METHOD_BLAS 0
#define METHOD_LOOPS 1
#define METHOD_LOOPS_OMP 2
#define MTIMESX_NOT_SET 0
#define MTIMESX_BLAS 1
#define MTIMESX_LOOPS 2
#define MTIMESX_LOOPS_OMP 3
#define MTIMESX_MATLAB 4
#define MTIMESX_SPEED 5
#define MTIMESX_SPEED_OMP 6
#define STRINGIZE(name) #name
#define TOKENSTRING(name) STRINGIZE(name)
#define DIRECTIVE_MAX 1000
#ifndef COMPILER
#define COMPILER (unknown)
#endif
/* Prototypes --------------------------------------------------------- */
mxArray *DoubleTimesDouble(mxArray *, char, mxArray *, char);
mxArray *FloatTimesFloat(mxArray *, char, mxArray *, char);
mxArray *mxCreateSharedDataCopy(const mxArray *pr);
char mxArrayToTrans(const mxArray *mx);
void *myRealloc(void *vp, mwSize_t n);
void mtimesx_logo(void);
mxArray *modestring(int);
/* Global Variables --------------------------------------------------- */
int mtimesx_mode = MTIMESX_MATLAB;
int max_threads = 0;
int threads_used = 0;
int debug = 0;
int debug_message = 0;
/* Functions ect for OpenMP implementations ------- */
#ifdef _OPENMP
#define OPENMP_ENABLED 1.0
/* Functions etc for non OpenMP implementations ----------------- */
/* The omp_get_num_procs() function is courtesy of Dirk-Jan Kroon */
/* and is based on his FEX submission maxNumCompThreads --------- */
#else
#define OPENMP_ENABLED 0.0
#define omp_get_wtick() 0.0
#define omp_get_wtime() ((double)clock()/((double)CLOCKS_PER_SEC))
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
int omp_get_num_procs( ) {
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return sysinfo.dwNumberOfProcessors;
}
#elif MACOS
#include <sys/param.h>
#include <sys/sysctl.h>
int omp_get_num_procs( ) {
int nm[2];
size_t len = 4;
uint32_t count;
nm[0] = CTL_HW; nm[1] = HW_AVAILCPU;
sysctl(nm, 2, &count, &len, NULL, 0);
if(count < 1) {
nm[1] = HW_NCPU;
sysctl(nm, 2, &count, &len, NULL, 0);
if(count < 1) { count = 1; }
}
return count;
}
#else
#include <unistd.h>
int omp_get_num_procs( ) {
return sysconf(_SC_NPROCESSORS_ONLN);
}
#endif
#endif
/*------------------------------------------------------------------------ */
/*------------------------------------------------------------------------ */
/*------------------------------------------------------------------------ */
/*------------------------------------------------------------------------ */
void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])
{
mxArray *A, *B, *C, *Araw, *Braw;
mxArray *rhs[4];
char transa, transb;
char *directive, *cp;
char transstring[2] = "_";
int unsupported = 0;
int i, j, k, got_directive, nrhs_old = nrhs;
int mtimesx_mode_new, max_threads_new,
already_set_mode, already_set_debug, already_set_threads;
mxArray *ans;
double threads;
/*-------------------------------------------------------------------------
* Check for proper number of inputs and outputs
*------------------------------------------------------------------------- */
if( nlhs > 1 ) {
mexErrMsgTxt("Must have at most 1 output.");
}
/*-------------------------------------------------------------------------
* If no inputs, just return the current mode
*------------------------------------------------------------------------- */
if( nrhs == 0 ) {
plhs[0] = modestring(mtimesx_mode);
return;
}
/*-------------------------------------------------------------------------
* Find out if any input is a directive
*------------------------------------------------------------------------- */
i = 0;
mtimesx_mode_new = MTIMESX_NOT_SET;
max_threads_new = 0;
already_set_mode = 0;
already_set_debug = 0;
already_set_threads = 0;
while( i < nrhs ) {
if( mxIsChar(prhs[i]) ) {
if( mxGetNumberOfElements(prhs[i]) > DIRECTIVE_MAX ) {
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1