- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the cblas sample in http://software.intel.com/en-us/articles/using-intel-mkl-in-your-c-program/mainly for c interface, so have a cblas wraper. It works fine when call cblas function. but tt seems bring a little pinprick when you call fortran interface function mkl_dcscmv().
The cblas wrapper is not needed actually, for example, the below code, you will get right result.
http://software.intel.com/en-us/forums/showthread.php?t=85690
Best Regards,
Ying
using System;
using System.Security;
using System.Runtime.InteropServices;
using mkl;
public class mkl_dcscmv
{
private mkl_dcscmv() { }
unsafe public static void Main(string[] args)
{
//create 4 arrays for storage of matrix
UIntPtr valSize = new UIntPtr(6);
int alignment = 32;
double* valP = (double*)MKL.mkl_malloc(valSize, alignment).ToPointer();
int* rowIndexP = (int*)MKL.mkl_malloc(valSize, alignment).ToPointer();
UIntPtr indexSize = new System.UIntPtr(3);
int* colbP = (int*)MKL.mkl_malloc(indexSize, alignment).ToPointer();
int* coleP = (int*)MKL.mkl_malloc(indexSize, alignment).ToPointer();
//create input array
double* xP = (double*)MKL.mkl_malloc(indexSize, alignment).ToPointer();
//create result array
double* resultP = (double*)MKL.mkl_malloc(indexSize, alignment).ToPointer();
//create matrix description
char[] matdesc = new char[] { 'G', ' ', ' ', 'C' }; //general, zero based indexing
//populate the arrays
double[] val = new double[] { 1, 3, 4, 5, 7, 6 };
int[] rowI = new int[] { 1, 2, 0, 2, 1, 2 };
int[] colb = new int[] { 0, 2, 4 };
int[] cole = new int[] { 2, 4, 6 };
for (int i = 0; i < val.Length; i++)
{
*(valP + i) = val;
*(rowIndexP + i) = rowI;
Console.WriteLine(*(valP + i) + "\t" + *(rowIndexP + i));
}
for (int i = 0; i < colb.Length; i++)
{
*(coleP + i) = cole;
*(colbP + i) = colb;
*(xP + i) = 3;
*(resultP + i) = 0;
Console.WriteLine(*(coleP + i) + "\t" + *(colbP + i));
}
int TransA = 'N'; // CBLAS.TRANSPOSE.NoTrans;
int rows = 3;
int cols = 3;
double alpha = 2.0, beta = 1.0;
CBLASNative.mkl_dcscmv(ref TransA, ref rows, ref cols, ref alpha, matdesc, valP, rowIndexP, colbP, coleP, xP, ref beta, resultP);
//CBLAS.mkl_dcscmv( TransA, rows, cols, alpha, matdesc, valP, rowIndexP, colbP, coleP, xP, beta, resultP);
for (int i = 0; i < rows; i++)
Console.WriteLine(*(resultP + i));
}
}
namespace mkl
{
//remove the wrapper;
/** CBLAS native declarations */
[SuppressUnmanagedCodeSecurity]
unsafe internal sealed class CBLASNative
{
private CBLASNative() {}
[DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl,
ExactSpelling = true, SetLastError = false)]
internal static extern void mkl_dcscmv(
ref int TransA, ref int rows, ref int cols, ref double alpha,
[In] char[] matdescra, [In] double* values,
[In] int* rowIndex, [In] int* colb,
[In] int* cole, [In] double* x,
ref double beta, [In, Out] double* y);
}
public sealed class MKL
{
public static UIntPtr mkl_malloc(UIntPtr size, int alignment)
{
return MKLNative.MKL_malloc(size, alignment);
}
public static void mkl_free(UIntPtr ptr)
{
MKLNative.MKL_free(ptr);
}
}
[SuppressUnmanagedCodeSecurity]
internal sealed class MKLNative
{
[DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl,
ExactSpelling = true, SetLastError = false)]
internal static extern UIntPtr MKL_malloc(UIntPtr size, int alignment);
[DllImport("mkl_rt", CallingConvention = CallingConvention.Cdecl,
ExactSpelling = true, SetLastError = false)]
internal static extern void MKL_free(UIntPtr ptr);
}
}
build and run it:
1 1
3 2
4 0
5 2
7 1
6 2
2 0
4 2
6 4
24
48
84
.... . .
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page