Commit 3796eb48 authored by kadir-hpi7's avatar kadir-hpi7
Browse files

I have completed mkl_shmem

parent 51e0a644
make;./mklspmm ../mtx/cp2k-h2o-e6.mtx 30 100 null
CFLAGS:=-O0 -g3 #FIXME
#CFLAGS:=-O1
#CFLAGS:=-O0 -g3
CFLAGS:=-O3
all: mklspmm
all: mklspgemm
#all: mklspmv mklspmm
mklspmv: mklspmv.o mmio.o
icc mklspmv.o mmio.o -o $@ -mkl -lm -offload-option,mic,ld,"-rpath /opt/intel/mic/myo/lib/ -rpath /opt/intel/mic/coi/device-linux-release/lib/"
mklspmm: mklspmm.o mmio.o
icc mklspmm.o mmio.o -o $@ -mkl -lm
mklspgemm: mklspgemm.o mmio.o
icc mklspgemm.o mmio.o -o $@ -mkl -lm
.c.o:
icc $(CFLAGS) $(OPTION) -o $@ -c $<
run:
./mv ../mtx/tinyA.mtx
clean:
@rm mmio.o mklspmv mklspmm mklspmm.o mklspmv.o
@rm mmio.o mklspgemm mklspgemm.o
make;./mklspmm ../mtx/smallA.mtx ../mtx/smallA.mtx 30 100 -1 null null perm5.txt PRINTMATRICES
make
./mklspgemm test.mtx test.mtx out.mtx 2 PRINT_YES
/*******************************************************************************
! Copyright(C) 1999-2013 Intel Corporation. All Rights Reserved.
!
! The source code, information and material ("Material") contained herein is
! owned by Intel Corporation or its suppliers or licensors, and title to such
! Material remains with Intel Corporation or its suppliers or licensors. The
! Material contains proprietary information of Intel or its suppliers and
! licensors. The Material is protected by worldwide copyright laws and treaty
! provisions. No part of the Material may be used, copied, reproduced,
! modified, published, uploaded, posted, transmitted, distributed or disclosed
! in any way without Intel's prior express written permission. No license
! under any patent, copyright or other intellectual property rights in the
! Material is granted to or conferred upon you, either expressly, by
! implication, inducement, estoppel or otherwise. Any license under such
! intellectual property rights must be express and approved by Intel in
! writing.
!
! *Third Party trademarks are the property of their respective owners.
!
! Unless otherwise agreed by Intel in writing, you may not remove or alter
! this notice or any other notice embedded in Materials by Intel or Intel's
! suppliers or licensors in any way.
!
!*******************************************************************************
! Content:
!
!******************************************************************************/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <math.h>
#include "mkl_example.h"
#include "mkl_cblas.h"
MKL_INT MaxValue(MKL_INT n, MKL_INT *x)
{
MKL_INT i, indmax;
indmax = x[0];
for (i = 1; i < n; i++)
if (indmax < x[i]) indmax = x[i];
return indmax;
} /* MaxValue */
MKL_INT GetVectorI(FILE *in_file, MKL_INT n, MKL_INT *x)
{
return GetValuesI( in_file, x, 0, n );
} /* GetVectorI */
MKL_INT GetVectorS(FILE *in_file, MKL_INT n, float *x, MKL_INT incx)
{
return GetValuesS( in_file, x, 1, 0, (1+(n-1)*abs(incx)) );
} /* GetVectorS */
MKL_INT GetVectorD(FILE *in_file, MKL_INT n, double *x, MKL_INT incx)
{
return GetValuesD( in_file, x, 1, 0, (1+(n-1)*abs(incx)) );
} /* GetVectorD */
MKL_INT GetVectorC(FILE *in_file, MKL_INT n, MKL_Complex8 *x, MKL_INT incx)
{
return GetValuesC( in_file, x, 1, 0, (1+(n-1)*abs(incx)) );
} /* GetVectorC */
MKL_INT GetVectorZ(FILE *in_file, MKL_INT n, MKL_Complex16 *x, MKL_INT incx)
{
return GetValuesZ( in_file, x, 1, 0, (1+(n-1)*abs(incx)) );
} /* GetVectorZ */
MKL_INT GetArrayS(FILE *in_file, CBLAS_ORDER *order, MKL_INT flag, MKL_INT *m, MKL_INT *n,
float *a, MKL_INT *lda)
{
MKL_INT i, j, number;
float *addr;
if( *order == CblasRowMajor ) {
if( flag == GENERAL_MATRIX ) {
for( i = 0; i < (*m); i++ ) {
addr = a + i*(*lda);
number = GetValuesS( in_file, addr, 1, 0, *n );
if( number != *n ) return 1;
} /* for */
} else if( flag == UPPER_MATRIX ) {
for (i = 0; i < (*m); i++) {
addr = a + i*(*lda);
number = GetValuesS( in_file, addr, 1, i, *n-i );
if( number != *n-i ) return 1;
} /* for */
} else if( flag == LOWER_MATRIX ) {
for (i = 0; i < (*m); i++) {
addr = a + i*(*lda);
number = GetValuesS( in_file, addr, 1, 0, i+1 );
if( number != i+1 ) return 1;
} /* for */
} /* if */
} else if( *order == CblasColMajor ) {
if( flag == GENERAL_MATRIX ) {
for( j = 0; j < (*n); j++ ) {
addr = a + j*(*lda);
number = GetValuesS( in_file, addr, 1, 0, *m );
if( number != *m ) return 1;
} /* for */
} else if( flag == UPPER_MATRIX ) {
for( j = 0; j < (*n); j++ ) {
addr = a + j*(*lda);
number = GetValuesS( in_file, addr, 1, 0, j+1 );
if( number != j+1 ) return 1;
} /* for */
} else if( flag == LOWER_MATRIX ) {
for( j = 0; j < (*n); j++ ) {
addr = a + j*(*lda);
number = GetValuesS( in_file, addr, 1, j, *m-j );
if( number != *m-j ) return 1;
} /* for */
} /* if */
} /* if */
return 0;
} /* GetArrayS */
MKL_INT GetArrayD(FILE *in_file, CBLAS_ORDER *order, MKL_INT flag, MKL_INT *m, MKL_INT *n,
double *a, MKL_INT *lda)
{
MKL_INT i, j, number;
double *addr;
if (*order == CblasRowMajor) {
if (flag == GENERAL_MATRIX) {
for (i = 0; i < (*m); i++) {
addr = a + i*(*lda);
number = GetValuesD( in_file, addr, 1, 0, *n );
if( number != *n ) return 1;
} /* for */
} else if (flag == UPPER_MATRIX) {
for (i = 0; i < (*m); i++) {
addr = a + i*(*lda);
number = GetValuesD( in_file, addr, 1, i, *n-i );
if( number != *n-i ) return 1;
} /* for */
} else if (flag == LOWER_MATRIX) {
for (i = 0; i < (*m); i++) {
addr = a + i*(*lda);
number = GetValuesD( in_file, addr, 1, 0, i+1 );
if( number != i+1 ) return 1;
} /* for */
} /* if */
} else if (*order == CblasColMajor) {
if (flag == GENERAL_MATRIX) {
for (j = 0; j < (*n); j++) {
addr = a + j*(*lda);
number = GetValuesD( in_file, addr, 1, 0, *m );
if( number != *m ) return 1;
} /* for */
} else if (flag == UPPER_MATRIX) {
for (j = 0; j < (*n); j++) {
addr = a + j*(*lda);
number = GetValuesD( in_file, addr, 1, 0, j+1 );
if( number != j+1 ) return 1;
} /* for */
} else if (flag == LOWER_MATRIX) {
for (j = 0; j < (*n); j++) {
addr = a + j*(*lda);
number = GetValuesD( in_file, addr, 1, j, *m-j );
if( number != *m-j ) return 1;
} /* for */
} /* if */
} /* if */
return 0;
} /* GetArrayD */
MKL_INT GetArrayC(FILE *in_file, CBLAS_ORDER *order, MKL_INT flag, MKL_INT *m, MKL_INT *n,
MKL_Complex8 *a, MKL_INT *lda)
{
MKL_INT i, j, number;
MKL_Complex8 *addr;
if (*order == CblasRowMajor) {
if (flag == GENERAL_MATRIX) {
for (i = 0; i < (*m); i++) {
addr = a + i*(*lda);
number = GetValuesC( in_file, addr, 1, 0, *n );
if( number != *n ) return 1;
} /* for */
} else if (flag == UPPER_MATRIX) {
for (i = 0; i < (*m); i++) {
addr = a + i*(*lda);
number = GetValuesC( in_file, addr, 1, i, *n-i );
if( number != *n-i ) return 1;
} /* for */
} else if (flag == LOWER_MATRIX) {
for (i = 0; i < (*m); i++) {
addr = a + i*(*lda);
number = GetValuesC( in_file, addr, 1, 0, i+1 );
if( number != i+1 ) return 1;
} /* for */
} /* if */
} else if (*order == CblasColMajor) {
if (flag == GENERAL_MATRIX) {
for (j = 0; j < (*n); j++) {
addr = a + j*(*lda);
number = GetValuesC( in_file, addr, 1, 0, *m );
if( number != *m ) return 1;
} /* for */
} else if (flag == UPPER_MATRIX) {
for (j = 0; j < (*n); j++) {
addr = a + j*(*lda);
number = GetValuesC( in_file, addr, 1, 0, j+1 );
if( number != j+1 ) return 1;
} /* for */
} else if (flag == LOWER_MATRIX) {
for (j = 0; j < (*n); j++) {
addr = a + j*(*lda);
number = GetValuesC( in_file, addr, 1, j, *m-j );
if( number != *m-j ) return 1;
} /* for */
} /* if */
} /* if */
return 0;
} /* GetArrayC */
MKL_INT GetArrayZ(FILE *in_file, CBLAS_ORDER *order, MKL_INT flag,
MKL_INT *m, MKL_INT *n, MKL_Complex16 *a, MKL_INT *lda)
{
MKL_INT i, j, number;
MKL_Complex16 *addr;
char buf[MAX_STRING_LEN];
if (*order == CblasRowMajor) {
if (flag == GENERAL_MATRIX) {
for (i = 0; i < (*m); i++) {
addr = a + i*(*lda);
number = GetValuesZ( in_file, addr, 1, 0, *n );
if( number != *n ) return 1;
} /* for */
} else if (flag == UPPER_MATRIX) {
for (i = 0; i < (*m); i++) {
addr = a + i*(*lda);
number = GetValuesZ( in_file, addr, 1, i, *n-i );
if( number != *n-i ) return 1;
} /* for */
} else if (flag == LOWER_MATRIX) {
for (i = 0; i < (*m); i++) {
addr = a + i*(*lda);
number = GetValuesZ( in_file, addr, 1, 0, i+1 );
if( number != i+1 ) return 1;
} /* for */
} /* if */
} else if(*order == CblasColMajor) {
if (flag == GENERAL_MATRIX) {
for (j = 0; j < (*n); j++) {
addr = a + j*(*lda);
number = GetValuesZ( in_file, addr, 1, 0, *m );
if( number != *m ) return 1;
} /* for */
} else if (flag == UPPER_MATRIX) {
for (j = 0; j < (*n); j++) {
addr = a + j*(*lda);
number = GetValuesZ( in_file, addr, 1, 0, j+1 );
if( number != j+1 ) return 1;
} /* for */
} else if (flag == LOWER_MATRIX) {
for (j = 0; j < (*n); j++) {
addr = a + j*(*lda);
number = GetValuesZ( in_file, addr, 1, j, *m-j );
if( number != *m-j ) return 1;
} /* for */
} /* if */
} /* if */
return 0;
} /* GetArrayZ */
MKL_INT GetBandArrayS(FILE *in_file, CBLAS_ORDER *order, MKL_INT kl, MKL_INT ku,
MKL_INT m, MKL_INT n, float *a, MKL_INT lda)
{
MKL_INT i, j;
MKL_INT kl1, ku1, i_start, j_start, j_end, ku_rows, kl_rows, number;
float *addr, *addr1;
char buf[MAX_STRING_LEN];
if (*order == CblasRowMajor) {
for( i = 0; i < MIN( m, n ); i++ ) {
addr = a + i*lda;
kl1 = ( i - kl <= 0 ) ? i : kl;
ku1 = ( i + ku >= n ) ? MAX(0,n-i-1) : ku;
j_start = kl - kl1;
j_end = j_start + kl1 + ku1;
addr1 = addr + j_start;
number = GetValuesS( in_file, addr1, 1, 0, j_end-j_start+1 );
if( number != j_end-j_start+1 ) return 1;
}
for( i = MIN( m, n ); i < MIN( m, MIN( m, n ) + kl); i++ ) {
addr = a + i*lda;
kl1 = n - i + kl;
j_start = ( kl > n ) ? kl - n : n - kl;
j_end = j_start + kl1 - 1;
addr1 = addr + j_start;
number = GetValuesS( in_file, addr1, 1, 0, j_end-j_start+1 );
if( number != j_end-j_start+1 ) return 1;
}
} else if (*order == CblasColMajor) {
i_start = (ku > n ) ? ku - n + 1 : 0;
ku_rows = (ku > n ) ? n - 1 : ku;
j_start = ku_rows;
for( i = 0; i < ku_rows; i++ ) {
j = j_start*lda; addr1 = a+i+i_start;
number = GetValuesS( in_file, addr1, lda, j, n-ku_rows );
if( number != n-ku_rows ) return 1;
j_start--;
}
j_end = MIN(m,n);
addr1 = a + ku;
number = GetValuesS( in_file, addr1, lda, 0, j_end );
if( number != j_end ) return 1;
kl_rows = ( kl <= m-1 ) ? kl : m - 1;
for ( i = 1; i < kl_rows+1; i++ ) {
kl1 = ( i+j_end <= m ) ? j_end : m - i;
addr1 = a + ku + i;
number = GetValuesS( in_file, addr1, lda, 0, kl1 );
if( number != kl1 ) return 1;
}
}
return 0;
} /* GetBandArrayS */
MKL_INT GetBandArrayD(FILE *in_file, CBLAS_ORDER *order, MKL_INT kl, MKL_INT ku,
MKL_INT m, MKL_INT n, double *a, MKL_INT lda)
{
MKL_INT i, j;
MKL_INT kl1, ku1, i_start, j_start, j_end, kl_rows, ku_rows, number;
double *addr, *addr1;
char buf[MAX_STRING_LEN];
if (*order == CblasRowMajor) {
for( i = 0; i < MIN( m, n ); i++ ) {
addr = a + i*lda;
kl1 = ( i - kl <= 0 ) ? i : kl;
ku1 = ( i + ku >= n ) ? MAX(0,n-i-1) : ku;
j_start = kl - kl1;
j_end = j_start + kl1 + ku1;
addr1 = addr + j_start;
number = GetValuesD( in_file, addr1, 1, 0, j_end-j_start+1 );
if( number != j_end-j_start+1 ) return 1;
}
for( i = MIN( m, n ); i < MIN( m, MIN( m, n ) + kl); i++ ) {
addr = a + i*lda;
kl1 = n - i + kl;
j_start = ( kl > n ) ? kl - n : n - kl;
j_end = j_start + kl1 - 1;
addr1 = addr + j_start;
number = GetValuesD( in_file, addr1, 1, 0, j_end-j_start+1 );
if( number != j_end-j_start+1 ) return 1;
}
} else if (*order == CblasColMajor) {
i_start = (ku > n ) ? ku - n + 1 : 0;
ku_rows = (ku > n ) ? n - 1 : ku;
j_start = ku_rows;
for( i = 0; i < ku_rows; i++ ) {
j = j_start*lda; addr1 = a+i+i_start;
number = GetValuesD( in_file, addr1, lda, j, n-ku_rows );
if( number != n-ku_rows ) return 1;
j_start--;
}
j_end = MIN(m,n);
addr1 = a+ku;
number = GetValuesD( in_file, addr1, lda, 0, j_end );
if( number != j_end ) return 1;
kl_rows = ( kl <= m-1 ) ? kl : m - 1;
for ( i = 1; i < kl_rows+1; i++ ) {
kl1 = ( i+j_end <= m ) ? j_end : m - i;
addr1 = a+ku+i;
number = GetValuesD( in_file, addr1, lda, 0, kl1 );
if( number != kl1 ) return 1;
}
} /* if */
return 0;
} /* GetBandArrayD */
MKL_INT GetBandArrayC(FILE *in_file, CBLAS_ORDER *order, MKL_INT kl, MKL_INT ku,
MKL_INT m, MKL_INT n, MKL_Complex8 *a, MKL_INT lda)
{
MKL_INT i, j;
MKL_INT kl1, ku1, i_start, j_start, j_end, ku_rows, kl_rows, number;
MKL_Complex8 *addr, *addr1;
char buf[MAX_STRING_LEN];
if (*order == CblasRowMajor) {
for( i = 0; i < MIN( m, n ); i++ ) {
addr = a + i*lda;
kl1 = ( i - kl <= 0 ) ? i : kl;
ku1 = ( i + ku >= n ) ? MAX(0,n-i-1) : ku;
j_start = kl - kl1;
j_end = j_start + kl1 + ku1;
addr1 = addr + j_start;
number = GetValuesC( in_file, addr1, 1, 0, j_end-j_start+1 );
if( number != j_end-j_start+1 ) return 1;
}
for( i = MIN( m, n ); i < MIN( m, MIN( m, n ) + kl); i++ ) {
addr = a + i*lda;
kl1 = n - i + kl;
j_start = ( kl > n ) ? kl - n : n - kl;
j_end = j_start + kl1 - 1;
addr1 = addr + j_start;
number = GetValuesC( in_file, addr1, 1, 0, j_end-j_start+1 );
if( number != j_end-j_start+1 ) return 1;
}
} else if (*order == CblasColMajor) {
i_start = (ku > n ) ? ku - n + 1 : 0;
ku_rows = (ku > n ) ? n - 1 : ku;
j_start = ku_rows;
for( i = 0; i < ku_rows; i++ ) {
j = j_start*lda; addr1 = a+i+i_start;
number = GetValuesC( in_file, addr1, lda, j, n-ku_rows );
if( number != n-ku_rows ) return 1;
j_start--;
}
j_end = MIN(m,n);
addr1 = a+ku;
number = GetValuesC( in_file, addr1, lda, 0, j_end );
if( number != j_end ) return 1;
kl_rows = ( kl <= m-1 ) ? kl : m - 1;
for ( i = 1; i < kl_rows+1; i++ ) {
kl1 = ( i+j_end <= m ) ? j_end : m - i;
addr1 = a+ku+i;
number = GetValuesC( in_file, addr1, lda, 0, kl1 );
if( number != kl1 ) return 1;
}
} /* if */
return 0;
} /* GetBandArrayC */
MKL_INT GetBandArrayZ(FILE *in_file, CBLAS_ORDER *order, MKL_INT kl, MKL_INT ku,
MKL_INT m, MKL_INT n, MKL_Complex16 *a, MKL_INT lda)
{
MKL_INT i, j;
MKL_INT kl1, ku1, i_start, j_start, j_end, ku_rows, kl_rows, number;
MKL_Complex16 *addr, *addr1;
if (*order == CblasRowMajor) {
for( i = 0; i < MIN( m, n ); i++ ) {
addr = a + i*lda;
kl1 = ( i - kl <= 0 ) ? i : kl;
ku1 = ( i + ku >= n ) ? MAX(0,n-i-1) : ku;
j_start = kl - kl1;
j_end = j_start + kl1 + ku1;
addr1 = addr + j_start;
number = GetValuesZ( in_file, addr1, 1, 0, j_end-j_start+1 );
if( number != j_end-j_start+1 ) return 1;
}
for( i = MIN( m, n ); i < MIN( m, MIN( m, n ) + kl); i++ ) {
addr = a + i*lda;
kl1 = n - i + kl;
j_start = ( kl > n ) ? kl - n : n - kl;
j_end = j_start + kl1 - 1;
addr1 = addr + j_start;
number = GetValuesZ( in_file, addr1, 1, 0, j_end-j_start+1 );
if( number != j_end-j_start+1 ) return 1;
}
} else if (*order == CblasColMajor) {
i_start = (ku > n ) ? ku - n + 1 : 0;
ku_rows = (ku > n ) ? n - 1 : ku;
j_start = ku_rows;
for( i = 0; i < ku_rows; i++ ) {
j = j_start*lda; addr1 = a+i+i_start;
number = GetValuesZ( in_file, addr1, lda, j, n-ku_rows );
if( number != n-ku_rows ) return 1;
j_start--;
}
j_end = MIN(m,n);
addr1 = a+ku;
number = GetValuesZ( in_file, addr1, lda, 0, j_end );
if( number != j_end ) return 1;
kl_rows = ( kl <= m-1 ) ? kl : m - 1;
for ( i = 1; i < kl_rows+1; i++ ) {
kl1 = ( i+j_end <= m ) ? j_end : m - i;
addr1 = a+ku+i;
number = GetValuesZ( in_file, addr1, lda, 0, kl1 );
if( number != kl1 ) return 1;
}
} /* if */
return 0;
} /* GetBandArrayZ */
MKL_INT GetValuesI( FILE *in_file, MKL_INT *in_array, MKL_INT begin, MKL_INT max_numbers )
{
MKL_INT i, counter=0;
int value;
char buf[MAX_STRING_LEN], *str;
do {
fgets( buf, MAX_STRING_LEN, in_file );
str = strtok( buf, " " );
if( str == NULL ){
printf( "\n File format is inappropriate\n");
return 0;
}
} while ( *str == COMMENTS );
for( i = 0; i < max_numbers; i++ ) {
if ( *str==COMMENTS ) break;
if( sscanf( str, "%d", &value) != 1 ){
printf( "\n File format is inappropriate\n" );
return 0;
}
in_array[begin+i]=(MKL_INT)value;
counter++;
if ( (str = strtok( NULL, " " )) == NULL ) break;
}
return counter;
}
MKL_INT GetValuesD( FILE *in_file, double *in_array, MKL_INT ld, MKL_INT begin, MKL_INT max_numbers )
{
MKL_INT i, counter=0;
double temp;
char buf[MAX_STRING_LEN], *str;
do {
fgets( buf, MAX_STRING_LEN, in_file );
str = strtok( buf, " " );
if( str == NULL ){
printf( "\n File format is inappropriate\n");
return 0;
}
} while ( *str == COMMENTS );
for( i = 0; i < max_numbers; i++ ) {
if ( *str==COMMENTS ) break;
if( sscanf( str, "%lf", &temp) != 1 ){
printf