Blame thirdparty/openblas/xianyi-OpenBLAS-e6e87a2/lapack/getrf/getrf_parallel.c

kusano 2b45e8
/*********************************************************************/
kusano 2b45e8
/* Copyright 2009, 2010 The University of Texas at Austin.           */
kusano 2b45e8
/* All rights reserved.                                              */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/* Redistribution and use in source and binary forms, with or        */
kusano 2b45e8
/* without modification, are permitted provided that the following   */
kusano 2b45e8
/* conditions are met:                                               */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*   1. Redistributions of source code must retain the above         */
kusano 2b45e8
/*      copyright notice, this list of conditions and the following  */
kusano 2b45e8
/*      disclaimer.                                                  */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*   2. Redistributions in binary form must reproduce the above      */
kusano 2b45e8
/*      copyright notice, this list of conditions and the following  */
kusano 2b45e8
/*      disclaimer in the documentation and/or other materials       */
kusano 2b45e8
/*      provided with the distribution.                              */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/*    THIS  SOFTWARE IS PROVIDED  BY THE  UNIVERSITY OF  TEXAS AT    */
kusano 2b45e8
/*    AUSTIN  ``AS IS''  AND ANY  EXPRESS OR  IMPLIED WARRANTIES,    */
kusano 2b45e8
/*    INCLUDING, BUT  NOT LIMITED  TO, THE IMPLIED  WARRANTIES OF    */
kusano 2b45e8
/*    MERCHANTABILITY  AND FITNESS FOR  A PARTICULAR  PURPOSE ARE    */
kusano 2b45e8
/*    DISCLAIMED.  IN  NO EVENT SHALL THE UNIVERSITY  OF TEXAS AT    */
kusano 2b45e8
/*    AUSTIN OR CONTRIBUTORS BE  LIABLE FOR ANY DIRECT, INDIRECT,    */
kusano 2b45e8
/*    INCIDENTAL,  SPECIAL, EXEMPLARY,  OR  CONSEQUENTIAL DAMAGES    */
kusano 2b45e8
/*    (INCLUDING, BUT  NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE    */
kusano 2b45e8
/*    GOODS  OR  SERVICES; LOSS  OF  USE,  DATA,  OR PROFITS;  OR    */
kusano 2b45e8
/*    BUSINESS INTERRUPTION) HOWEVER CAUSED  AND ON ANY THEORY OF    */
kusano 2b45e8
/*    LIABILITY, WHETHER  IN CONTRACT, STRICT  LIABILITY, OR TORT    */
kusano 2b45e8
/*    (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT    */
kusano 2b45e8
/*    OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF ADVISED  OF  THE    */
kusano 2b45e8
/*    POSSIBILITY OF SUCH DAMAGE.                                    */
kusano 2b45e8
/*                                                                   */
kusano 2b45e8
/* The views and conclusions contained in the software and           */
kusano 2b45e8
/* documentation are those of the authors and should not be          */
kusano 2b45e8
/* interpreted as representing official policies, either expressed   */
kusano 2b45e8
/* or implied, of The University of Texas at Austin.                 */
kusano 2b45e8
/*********************************************************************/
kusano 2b45e8
kusano 2b45e8
#include <stdio.h></stdio.h>
kusano 2b45e8
#include "common.h"
kusano 2b45e8
kusano 2b45e8
static FLOAT dm1 = -1.;
kusano 2b45e8
kusano 2b45e8
double sqrt(double);
kusano 2b45e8
kusano 2b45e8
#ifndef CACHE_LINE_SIZE
kusano 2b45e8
#define CACHE_LINE_SIZE 8
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#ifndef DIVIDE_RATE
kusano 2b45e8
#define DIVIDE_RATE 2
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#define GEMM_PQ  MAX(GEMM_P, GEMM_Q)
kusano 2b45e8
#define REAL_GEMM_R (GEMM_R - GEMM_PQ)
kusano 2b45e8
kusano 2b45e8
#ifndef GETRF_FACTOR
kusano 2b45e8
#define GETRF_FACTOR 0.75
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
#undef  GETRF_FACTOR
kusano 2b45e8
#define GETRF_FACTOR 1.00
kusano 2b45e8
kusano 2b45e8
static inline long FORMULA1(long M, long N, long IS, long BK, long T) {
kusano 2b45e8
kusano 2b45e8
  double m = (double)(M - IS - BK);
kusano 2b45e8
  double n = (double)(N - IS - BK);
kusano 2b45e8
  double b = (double)BK;
kusano 2b45e8
  double a = (double)T;
kusano 2b45e8
kusano 2b45e8
  return (long)((n + GETRF_FACTOR * m * b * (1. - a) / (b + m)) / a);
kusano 2b45e8
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
#define FORMULA2(M, N, IS, BK, T) (BLASLONG)((double)(N - IS + BK) * (1. - sqrt(1. - 1. / (double)(T))))
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
static void inner_basic_thread(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa, FLOAT *sb, BLASLONG mypos){
kusano 2b45e8
kusano 2b45e8
  BLASLONG is, min_i;
kusano 2b45e8
  BLASLONG js, min_j;
kusano 2b45e8
  BLASLONG jjs, min_jj;
kusano 2b45e8
kusano 2b45e8
  BLASLONG m = args -> m;
kusano 2b45e8
  BLASLONG n = args -> n;
kusano 2b45e8
  BLASLONG k = args -> k;
kusano 2b45e8
kusano 2b45e8
  BLASLONG lda = args -> lda;
kusano 2b45e8
  BLASLONG off = args -> ldb;
kusano 2b45e8
kusano 2b45e8
  FLOAT *b = (FLOAT *)args -> b + (k          ) * COMPSIZE;
kusano 2b45e8
  FLOAT *c = (FLOAT *)args -> b + (    k * lda) * COMPSIZE;
kusano 2b45e8
  FLOAT *d = (FLOAT *)args -> b + (k + k * lda) * COMPSIZE;
kusano 2b45e8
  FLOAT *sbb = sb;
kusano 2b45e8
kusano 2b45e8
  volatile BLASLONG *flag = (volatile BLASLONG *)args -> d;
kusano 2b45e8
kusano 2b45e8
  blasint *ipiv = (blasint *)args -> c;
kusano 2b45e8
kusano 2b45e8
  if (range_n) {
kusano 2b45e8
    n      = range_n[1] - range_n[0];
kusano 2b45e8
    c     += range_n[0] * lda * COMPSIZE;
kusano 2b45e8
    d     += range_n[0] * lda * COMPSIZE;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (args -> a == NULL) {
kusano 2b45e8
    TRSM_ILTCOPY(k, k, (FLOAT *)args -> b, lda, 0, sb);
kusano 2b45e8
    sbb = (FLOAT *)((((long)(sb + k * k * COMPSIZE) + GEMM_ALIGN) & ~GEMM_ALIGN) + GEMM_OFFSET_B);
kusano 2b45e8
  } else {
kusano 2b45e8
    sb  = (FLOAT *)args -> a;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  for (js = 0; js < n; js += REAL_GEMM_R) {
kusano 2b45e8
    min_j = n - js;
kusano 2b45e8
    if (min_j > REAL_GEMM_R) min_j = REAL_GEMM_R;
kusano 2b45e8
kusano 2b45e8
    for (jjs = js; jjs < js + min_j; jjs += GEMM_UNROLL_N){
kusano 2b45e8
      min_jj = js + min_j - jjs;
kusano 2b45e8
      if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
kusano 2b45e8
      
kusano 2b45e8
      if (GEMM_UNROLL_N <= 8) {
kusano 2b45e8
kusano 2b45e8
	LASWP_NCOPY(min_jj, off + 1, off + k, 
kusano 2b45e8
		    c + (- off + jjs * lda) * COMPSIZE, lda,
kusano 2b45e8
		    ipiv, sbb + k * (jjs - js) * COMPSIZE);
kusano 2b45e8
kusano 2b45e8
      } else {
kusano 2b45e8
kusano 2b45e8
	LASWP_PLUS(min_jj, off + 1, off + k, ZERO, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		   ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		   c + (- off + jjs * lda) * COMPSIZE, lda, NULL, 0, ipiv, 1);
kusano 2b45e8
	
kusano 2b45e8
	GEMM_ONCOPY (k, min_jj, c + jjs * lda * COMPSIZE, lda, sbb + (jjs - js) * k * COMPSIZE);
kusano 2b45e8
kusano 2b45e8
      }
kusano 2b45e8
kusano 2b45e8
      for (is = 0; is < k; is += GEMM_P) {
kusano 2b45e8
	min_i = k - is;
kusano 2b45e8
	if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	
kusano 2b45e8
	TRSM_KERNEL_LT(min_i, min_jj, k, dm1,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		       ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		       sb  + k * is * COMPSIZE,
kusano 2b45e8
		       sbb + (jjs - js) * k * COMPSIZE, 
kusano 2b45e8
		       c   + (is + jjs * lda) * COMPSIZE, lda, is);
kusano 2b45e8
      }
kusano 2b45e8
    }
kusano 2b45e8
kusano 2b45e8
    if ((js + REAL_GEMM_R >= n) && (mypos >= 0)) flag[mypos * CACHE_LINE_SIZE] = 0;
kusano 2b45e8
kusano 2b45e8
    for (is = 0; is < m; is += GEMM_P){
kusano 2b45e8
      min_i = m - is;
kusano 2b45e8
      if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
      
kusano 2b45e8
      GEMM_ITCOPY (k, min_i, b + is * COMPSIZE, lda, sa);
kusano 2b45e8
      
kusano 2b45e8
      GEMM_KERNEL_N(min_i, min_j, k, dm1,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		    ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		    sa, sbb, d + (is + js * lda) * COMPSIZE, lda);
kusano 2b45e8
    }
kusano 2b45e8
  }
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
/* Non blocking implementation */
kusano 2b45e8
kusano 2b45e8
typedef struct {
kusano 2b45e8
  volatile BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE];
kusano 2b45e8
} job_t;
kusano 2b45e8
kusano 2b45e8
#define ICOPY_OPERATION(M, N, A, LDA, X, Y, BUFFER) GEMM_ITCOPY(M, N, (FLOAT *)(A) + ((Y) + (X) * (LDA)) * COMPSIZE, LDA, BUFFER);
kusano 2b45e8
#define OCOPY_OPERATION(M, N, A, LDA, X, Y, BUFFER) GEMM_ONCOPY(M, N, (FLOAT *)(A) + ((X) + (Y) * (LDA)) * COMPSIZE, LDA, BUFFER);
kusano 2b45e8
kusano 2b45e8
#ifndef COMPLEX
kusano 2b45e8
#define KERNEL_OPERATION(M, N, K, SA, SB, C, LDC, X, Y) \
kusano 2b45e8
	GEMM_KERNEL_N(M, N, K, dm1, SA, SB, (FLOAT *)(C) + ((X) + (Y) * LDC) * COMPSIZE, LDC)
kusano 2b45e8
#else
kusano 2b45e8
#define KERNEL_OPERATION(M, N, K, SA, SB, C, LDC, X, Y) \
kusano 2b45e8
	GEMM_KERNEL_N(M, N, K, dm1, ZERO, SA, SB, (FLOAT *)(C) + ((X) + (Y) * LDC) * COMPSIZE, LDC)
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
static int inner_advanced_thread(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa, FLOAT *sb, BLASLONG mypos){
kusano 2b45e8
kusano 2b45e8
  job_t *job = (job_t *)args -> common;
kusano 2b45e8
kusano 2b45e8
  BLASLONG xxx, bufferside;
kusano 2b45e8
kusano 2b45e8
  FLOAT *buffer[DIVIDE_RATE];
kusano 2b45e8
kusano 2b45e8
  BLASLONG jjs, min_jj, div_n;
kusano 2b45e8
kusano 2b45e8
  BLASLONG i, current;
kusano 2b45e8
  BLASLONG is, min_i;
kusano 2b45e8
kusano 2b45e8
  BLASLONG m, n_from, n_to;
kusano 2b45e8
  BLASLONG k = args -> k;
kusano 2b45e8
kusano 2b45e8
  BLASLONG lda = args -> lda;
kusano 2b45e8
  BLASLONG off = args -> ldb;
kusano 2b45e8
kusano 2b45e8
  FLOAT *a = (FLOAT *)args -> b + (k          ) * COMPSIZE;
kusano 2b45e8
  FLOAT *b = (FLOAT *)args -> b + (    k * lda) * COMPSIZE;
kusano 2b45e8
  FLOAT *c = (FLOAT *)args -> b + (k + k * lda) * COMPSIZE;
kusano 2b45e8
  FLOAT *sbb= sb;
kusano 2b45e8
kusano 2b45e8
  blasint *ipiv = (blasint *)args -> c;
kusano 2b45e8
kusano 2b45e8
  volatile BLASLONG *flag = (volatile BLASLONG *)args -> d;
kusano 2b45e8
kusano 2b45e8
  if (args -> a == NULL) {
kusano 2b45e8
    TRSM_ILTCOPY(k, k, (FLOAT *)args -> b, lda, 0, sb);
kusano 2b45e8
    sbb = (FLOAT *)((((long)(sb + k * k * COMPSIZE) + GEMM_ALIGN) & ~GEMM_ALIGN) + GEMM_OFFSET_B);
kusano 2b45e8
  } else {
kusano 2b45e8
    sb  = (FLOAT *)args -> a;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  m      = range_m[1] - range_m[0];
kusano 2b45e8
  n_from = range_n[mypos + 0];
kusano 2b45e8
  n_to   = range_n[mypos + 1];
kusano 2b45e8
kusano 2b45e8
  a     += range_m[0] * COMPSIZE;
kusano 2b45e8
  c     += range_m[0] * COMPSIZE;
kusano 2b45e8
kusano 2b45e8
  div_n = (n_to - n_from + DIVIDE_RATE - 1) / DIVIDE_RATE;
kusano 2b45e8
  
kusano 2b45e8
  buffer[0] = sbb;
kusano 2b45e8
kusano 2b45e8
kusano 2b45e8
  for (i = 1; i < DIVIDE_RATE; i++) {
kusano 2b45e8
    buffer[i] = buffer[i - 1] + GEMM_Q * ((div_n + GEMM_UNROLL_N - 1) & ~(GEMM_UNROLL_N - 1)) * COMPSIZE;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  for (xxx = n_from, bufferside = 0; xxx < n_to; xxx += div_n, bufferside ++) {
kusano 2b45e8
    
kusano 2b45e8
    for (i = 0; i < args -> nthreads; i++)
kusano 2b45e8
      while (job[mypos].working[i][CACHE_LINE_SIZE * bufferside]) {};
kusano 2b45e8
    
kusano 2b45e8
    for(jjs = xxx; jjs < MIN(n_to, xxx + div_n); jjs += min_jj){
kusano 2b45e8
      min_jj = MIN(n_to, xxx + div_n) - jjs;
kusano 2b45e8
      if (min_jj > GEMM_UNROLL_N) min_jj = GEMM_UNROLL_N;
kusano 2b45e8
kusano 2b45e8
      if (GEMM_UNROLL_N <= 8) {
kusano 2b45e8
kusano 2b45e8
	LASWP_NCOPY(min_jj, off + 1, off + k, 
kusano 2b45e8
		    b + (- off + jjs * lda) * COMPSIZE, lda,
kusano 2b45e8
		    ipiv, buffer[bufferside] + (jjs - xxx) * k * COMPSIZE);
kusano 2b45e8
kusano 2b45e8
      } else {
kusano 2b45e8
kusano 2b45e8
	LASWP_PLUS(min_jj, off + 1, off + k, ZERO, 
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		   ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		   b + (- off + jjs * lda) * COMPSIZE, lda, NULL, 0, ipiv, 1);
kusano 2b45e8
	
kusano 2b45e8
	GEMM_ONCOPY (k, min_jj, b + jjs * lda * COMPSIZE, lda, 
kusano 2b45e8
		     buffer[bufferside] + (jjs - xxx) * k * COMPSIZE);
kusano 2b45e8
      }
kusano 2b45e8
kusano 2b45e8
      for (is = 0; is < k; is += GEMM_P) {
kusano 2b45e8
	min_i = k - is;
kusano 2b45e8
	if (min_i > GEMM_P) min_i = GEMM_P;
kusano 2b45e8
	
kusano 2b45e8
	TRSM_KERNEL_LT(min_i, min_jj, k, dm1,
kusano 2b45e8
#ifdef COMPLEX
kusano 2b45e8
		       ZERO,
kusano 2b45e8
#endif
kusano 2b45e8
		       sb + k * is * COMPSIZE,
kusano 2b45e8
		       buffer[bufferside] + (jjs - xxx) * k * COMPSIZE, 
kusano 2b45e8
		       b   + (is + jjs * lda) * COMPSIZE, lda, is);
kusano 2b45e8
      }
kusano 2b45e8
    }
kusano 2b45e8
	
kusano 2b45e8
    for (i = 0; i < args -> nthreads; i++)
kusano 2b45e8
      job[mypos].working[i][CACHE_LINE_SIZE * bufferside] = (BLASLONG)buffer[bufferside];
kusano 2b45e8
kusano 2b45e8
  }
kusano 2b45e8
  
kusano 2b45e8
  flag[mypos * CACHE_LINE_SIZE] = 0;
kusano 2b45e8
  
kusano 2b45e8
  if (m == 0) {
kusano 2b45e8
    for (xxx = 0; xxx < DIVIDE_RATE; xxx++) {
kusano 2b45e8
      job[mypos].working[mypos][CACHE_LINE_SIZE * xxx] = 0;
kusano 2b45e8
    }
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  for(is = 0; is < m; is += min_i){
kusano 2b45e8
    min_i = m - is;
kusano 2b45e8
    if (min_i >= GEMM_P * 2) {
kusano 2b45e8
      min_i = GEMM_P;
kusano 2b45e8
    } else 
kusano 2b45e8
      if (min_i > GEMM_P) {
kusano 2b45e8
	min_i = ((min_i + 1) / 2 + GEMM_UNROLL_M - 1) & ~(GEMM_UNROLL_M - 1);
kusano 2b45e8
      }
kusano 2b45e8
      
kusano 2b45e8
      ICOPY_OPERATION(k, min_i, a, lda, 0, is, sa);
kusano 2b45e8
      
kusano 2b45e8
      current = mypos;
kusano 2b45e8
kusano 2b45e8
      do {
kusano 2b45e8
	
kusano 2b45e8
	div_n = (range_n[current + 1]  - range_n[current] + DIVIDE_RATE - 1) / DIVIDE_RATE;
kusano 2b45e8
	
kusano 2b45e8
	for (xxx = range_n[current], bufferside = 0; xxx < range_n[current + 1]; xxx += div_n, bufferside ++) {
kusano 2b45e8
	  
kusano 2b45e8
	  if ((current != mypos) && (!is)) {
kusano 2b45e8
	    	    while(job[current].working[mypos][CACHE_LINE_SIZE * bufferside] == 0) {};
kusano 2b45e8
	  }
kusano 2b45e8
kusano 2b45e8
	  KERNEL_OPERATION(min_i, MIN(range_n[current + 1] - xxx, div_n), k,
kusano 2b45e8
			   sa, (FLOAT *)job[current].working[mypos][CACHE_LINE_SIZE * bufferside],
kusano 2b45e8
			   c, lda, is, xxx);
kusano 2b45e8
	  
kusano 2b45e8
	  if (is + min_i >= m) {
kusano 2b45e8
	    job[current].working[mypos][CACHE_LINE_SIZE * bufferside] = 0;
kusano 2b45e8
	  }
kusano 2b45e8
	}
kusano 2b45e8
	
kusano 2b45e8
	current ++;
kusano 2b45e8
	if (current >= args -> nthreads) current = 0;
kusano 2b45e8
	
kusano 2b45e8
      } while (current != mypos);
kusano 2b45e8
  }
kusano 2b45e8
  
kusano 2b45e8
  for (i = 0; i < args -> nthreads; i++) {
kusano 2b45e8
    for (xxx = 0; xxx < DIVIDE_RATE; xxx++) {
kusano 2b45e8
      while (job[mypos].working[i][CACHE_LINE_SIZE * xxx] ) {};
kusano 2b45e8
    }
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  return 0;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
#if 1
kusano 2b45e8
kusano 2b45e8
blasint CNAME(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa, FLOAT *sb, BLASLONG myid) {
kusano 2b45e8
kusano 2b45e8
  BLASLONG m, n, mn, lda, offset;
kusano 2b45e8
  BLASLONG init_bk, next_bk, range_n_mine[2], range_n_new[2];
kusano 2b45e8
  blasint *ipiv, iinfo, info;
kusano 2b45e8
  int mode;
kusano 2b45e8
  blas_arg_t newarg;
kusano 2b45e8
kusano 2b45e8
  FLOAT *a, *sbb;
kusano 2b45e8
  FLOAT dummyalpha[2] = {ZERO, ZERO};
kusano 2b45e8
kusano 2b45e8
  blas_queue_t queue[MAX_CPU_NUMBER];
kusano 2b45e8
kusano 2b45e8
  BLASLONG range_M[MAX_CPU_NUMBER + 1];
kusano 2b45e8
  BLASLONG range_N[MAX_CPU_NUMBER + 1];
kusano 2b45e8
kusano 2b45e8
  job_t        job[MAX_CPU_NUMBER];
kusano 2b45e8
kusano 2b45e8
  BLASLONG width, nn, mm;
kusano 2b45e8
  BLASLONG i, j, k, is, bk;
kusano 2b45e8
kusano 2b45e8
  BLASLONG num_cpu;
kusano 2b45e8
kusano 2b45e8
  volatile BLASLONG flag[MAX_CPU_NUMBER * CACHE_LINE_SIZE] __attribute__((aligned(128)));
kusano 2b45e8
kusano 2b45e8
#ifndef COMPLEX
kusano 2b45e8
#ifdef XDOUBLE
kusano 2b45e8
  mode  =  BLAS_XDOUBLE | BLAS_REAL;
kusano 2b45e8
#elif defined(DOUBLE)
kusano 2b45e8
  mode  =  BLAS_DOUBLE  | BLAS_REAL;
kusano 2b45e8
#else
kusano 2b45e8
  mode  =  BLAS_SINGLE  | BLAS_REAL;
kusano 2b45e8
#endif  
kusano 2b45e8
#else
kusano 2b45e8
#ifdef XDOUBLE
kusano 2b45e8
  mode  =  BLAS_XDOUBLE | BLAS_COMPLEX;
kusano 2b45e8
#elif defined(DOUBLE)
kusano 2b45e8
  mode  =  BLAS_DOUBLE  | BLAS_COMPLEX;
kusano 2b45e8
#else
kusano 2b45e8
  mode  =  BLAS_SINGLE  | BLAS_COMPLEX;
kusano 2b45e8
#endif  
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
  m    = args -> m;
kusano 2b45e8
  n    = args -> n;
kusano 2b45e8
  a    = (FLOAT *)args -> a;
kusano 2b45e8
  lda  = args -> lda;
kusano 2b45e8
  ipiv = (blasint *)args -> c;
kusano 2b45e8
  offset = 0;
kusano 2b45e8
kusano 2b45e8
  if (range_n) {
kusano 2b45e8
    m     -= range_n[0];
kusano 2b45e8
    n      = range_n[1] - range_n[0];
kusano 2b45e8
    offset = range_n[0];
kusano 2b45e8
    a     += range_n[0] * (lda + 1) * COMPSIZE;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (m <= 0 || n <= 0) return 0;
kusano 2b45e8
  
kusano 2b45e8
  newarg.c   = ipiv;
kusano 2b45e8
  newarg.lda = lda;
kusano 2b45e8
  newarg.common   = (void *)job;
kusano 2b45e8
kusano 2b45e8
  info = 0;
kusano 2b45e8
kusano 2b45e8
  mn = MIN(m, n);
kusano 2b45e8
kusano 2b45e8
  init_bk = (mn / 2 + GEMM_UNROLL_N - 1) & ~(GEMM_UNROLL_N - 1);
kusano 2b45e8
  if (init_bk > GEMM_Q) init_bk = GEMM_Q;
kusano 2b45e8
kusano 2b45e8
  if (init_bk <= GEMM_UNROLL_N) {
kusano 2b45e8
    info = GETF2(args, NULL, range_n, sa, sb, 0);
kusano 2b45e8
    return info;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  next_bk = init_bk;
kusano 2b45e8
kusano 2b45e8
  bk = mn;
kusano 2b45e8
  if (bk > next_bk) bk = next_bk;
kusano 2b45e8
  
kusano 2b45e8
  range_n_new[0] = offset;
kusano 2b45e8
  range_n_new[1] = offset + bk;
kusano 2b45e8
  
kusano 2b45e8
  iinfo   = CNAME(args, NULL, range_n_new, sa, sb, 0);
kusano 2b45e8
  
kusano 2b45e8
  if (iinfo && !info) info = iinfo;
kusano 2b45e8
  
kusano 2b45e8
  TRSM_ILTCOPY(bk, bk, a, lda, 0, sb);
kusano 2b45e8
kusano 2b45e8
  sbb = (FLOAT *)((((long)(sb + bk * bk * COMPSIZE) + GEMM_ALIGN) & ~GEMM_ALIGN) + GEMM_OFFSET_B);
kusano 2b45e8
  
kusano 2b45e8
  is = 0;
kusano 2b45e8
  num_cpu = 0;
kusano 2b45e8
kusano 2b45e8
  while (is < mn) {
kusano 2b45e8
    
kusano 2b45e8
    width  = (FORMULA1(m, n, is, bk, args -> nthreads) + GEMM_UNROLL_N - 1) & ~(GEMM_UNROLL_N - 1);
kusano 2b45e8
    if (width > mn - is - bk) width = mn - is - bk;
kusano 2b45e8
kusano 2b45e8
    if (width < bk) {
kusano 2b45e8
      next_bk = (FORMULA2(m, n, is, bk, args -> nthreads) + GEMM_UNROLL_N) & ~(GEMM_UNROLL_N - 1);
kusano 2b45e8
      
kusano 2b45e8
      if (next_bk > bk) next_bk = bk;
kusano 2b45e8
kusano 2b45e8
      width = next_bk;
kusano 2b45e8
      if (width > mn - is - bk) width = mn - is - bk;
kusano 2b45e8
    }
kusano 2b45e8
    
kusano 2b45e8
    if (num_cpu > 0) exec_blas_async_wait(num_cpu, &queue[0]);
kusano 2b45e8
kusano 2b45e8
    mm = m - bk - is;
kusano 2b45e8
    nn = n - bk - is;
kusano 2b45e8
kusano 2b45e8
    newarg.a   = sb;
kusano 2b45e8
    newarg.b   = a + (is + is * lda) * COMPSIZE;
kusano 2b45e8
    newarg.d   = (void *)flag;
kusano 2b45e8
    newarg.m   = mm;
kusano 2b45e8
    newarg.n   = nn;
kusano 2b45e8
    newarg.k   = bk;
kusano 2b45e8
    newarg.ldb = is + offset;
kusano 2b45e8
    
kusano 2b45e8
    nn -= width;
kusano 2b45e8
kusano 2b45e8
    range_n_mine[0] = 0;
kusano 2b45e8
    range_n_mine[1] = width;
kusano 2b45e8
kusano 2b45e8
    range_N[0] = width;
kusano 2b45e8
    range_M[0] = 0;
kusano 2b45e8
kusano 2b45e8
    num_cpu  = 0;
kusano 2b45e8
    
kusano 2b45e8
    while (nn > 0){
kusano 2b45e8
      
kusano 2b45e8
      if (mm >= nn) {
kusano 2b45e8
kusano 2b45e8
	width  = blas_quickdivide(nn + args -> nthreads - num_cpu, args -> nthreads - num_cpu - 1);
kusano 2b45e8
	if (nn < width) width = nn;
kusano 2b45e8
	nn -= width;
kusano 2b45e8
	range_N[num_cpu + 1] = range_N[num_cpu] + width;
kusano 2b45e8
	
kusano 2b45e8
	width  = blas_quickdivide(mm + args -> nthreads - num_cpu, args -> nthreads - num_cpu - 1);
kusano 2b45e8
	if (mm < width) width = mm;
kusano 2b45e8
	if (nn <=    0) width = mm;
kusano 2b45e8
	mm -= width;
kusano 2b45e8
	range_M[num_cpu + 1] = range_M[num_cpu] + width;
kusano 2b45e8
kusano 2b45e8
      } else {
kusano 2b45e8
kusano 2b45e8
	width  = blas_quickdivide(mm + args -> nthreads - num_cpu, args -> nthreads - num_cpu - 1);
kusano 2b45e8
	if (mm < width) width = mm;
kusano 2b45e8
	mm -= width;
kusano 2b45e8
	range_M[num_cpu + 1] = range_M[num_cpu] + width;
kusano 2b45e8
kusano 2b45e8
	width  = blas_quickdivide(nn + args -> nthreads - num_cpu, args -> nthreads - num_cpu - 1);
kusano 2b45e8
	if (nn < width) width = nn;
kusano 2b45e8
	if (mm <=    0) width = nn;
kusano 2b45e8
	nn -= width;
kusano 2b45e8
	range_N[num_cpu + 1] = range_N[num_cpu] + width;
kusano 2b45e8
	
kusano 2b45e8
      }
kusano 2b45e8
kusano 2b45e8
      queue[num_cpu].mode    = mode;
kusano 2b45e8
      queue[num_cpu].routine = inner_advanced_thread;
kusano 2b45e8
      queue[num_cpu].args    = &newarg;
kusano 2b45e8
      queue[num_cpu].range_m = &range_M[num_cpu];
kusano 2b45e8
      queue[num_cpu].range_n = &range_N[0];
kusano 2b45e8
      queue[num_cpu].sa      = NULL;
kusano 2b45e8
      queue[num_cpu].sb      = NULL;
kusano 2b45e8
      queue[num_cpu].next    = &queue[num_cpu + 1];
kusano 2b45e8
      flag[num_cpu * CACHE_LINE_SIZE] = 1;
kusano 2b45e8
      
kusano 2b45e8
      num_cpu ++;
kusano 2b45e8
kusano 2b45e8
    }
kusano 2b45e8
    
kusano 2b45e8
    newarg.nthreads = num_cpu;
kusano 2b45e8
    
kusano 2b45e8
    if (num_cpu > 0) {
kusano 2b45e8
      for (j = 0; j < num_cpu; j++) {
kusano 2b45e8
	for (i = 0; i < num_cpu; i++) {
kusano 2b45e8
	  for (k = 0; k < DIVIDE_RATE; k++) {
kusano 2b45e8
	    job[j].working[i][CACHE_LINE_SIZE * k] = 0;
kusano 2b45e8
	  }
kusano 2b45e8
	}
kusano 2b45e8
      }
kusano 2b45e8
    }
kusano 2b45e8
kusano 2b45e8
    is += bk;
kusano 2b45e8
kusano 2b45e8
    bk = mn - is;
kusano 2b45e8
    if (bk > next_bk) bk = next_bk;
kusano 2b45e8
    
kusano 2b45e8
    range_n_new[0] = offset + is;
kusano 2b45e8
    range_n_new[1] = offset + is + bk;
kusano 2b45e8
kusano 2b45e8
    if (num_cpu > 0) {
kusano 2b45e8
kusano 2b45e8
      queue[num_cpu - 1].next = NULL;
kusano 2b45e8
      
kusano 2b45e8
      exec_blas_async(0, &queue[0]);
kusano 2b45e8
      
kusano 2b45e8
      inner_basic_thread(&newarg, NULL, range_n_mine, sa, sbb, -1);
kusano 2b45e8
      
kusano 2b45e8
      iinfo   = GETRF_SINGLE(args, NULL, range_n_new, sa, sbb, 0);
kusano 2b45e8
      
kusano 2b45e8
      if (iinfo && !info) info = iinfo + is;
kusano 2b45e8
kusano 2b45e8
      for (i = 0; i < num_cpu; i ++) while (flag[i * CACHE_LINE_SIZE]) {};
kusano 2b45e8
kusano 2b45e8
      TRSM_ILTCOPY(bk, bk, a + (is +  is * lda) * COMPSIZE, lda, 0, sb);
kusano 2b45e8
kusano 2b45e8
    } else {
kusano 2b45e8
kusano 2b45e8
      inner_basic_thread(&newarg, NULL, range_n_mine, sa, sbb, -1);
kusano 2b45e8
kusano 2b45e8
      iinfo   = GETRF_SINGLE(args, NULL, range_n_new, sa, sbb, 0);
kusano 2b45e8
kusano 2b45e8
      if (iinfo && !info) info = iinfo + is;
kusano 2b45e8
    
kusano 2b45e8
    }
kusano 2b45e8
    
kusano 2b45e8
  }
kusano 2b45e8
  
kusano 2b45e8
  next_bk = init_bk;
kusano 2b45e8
  is = 0;
kusano 2b45e8
  
kusano 2b45e8
  while (is < mn) {
kusano 2b45e8
    
kusano 2b45e8
    bk = mn - is;
kusano 2b45e8
    if (bk > next_bk) bk = next_bk;
kusano 2b45e8
    
kusano 2b45e8
    width  = (FORMULA1(m, n, is, bk, args -> nthreads) + GEMM_UNROLL_N - 1) & ~(GEMM_UNROLL_N - 1);
kusano 2b45e8
    if (width > mn - is - bk) width = mn - is - bk;
kusano 2b45e8
kusano 2b45e8
    if (width < bk) {
kusano 2b45e8
      next_bk = (FORMULA2(m, n, is, bk, args -> nthreads) + GEMM_UNROLL_N) & ~(GEMM_UNROLL_N - 1);
kusano 2b45e8
      if (next_bk > bk) next_bk = bk;
kusano 2b45e8
    }
kusano 2b45e8
kusano 2b45e8
    blas_level1_thread(mode, bk, is + bk + offset + 1, mn + offset, (void *)dummyalpha, 
kusano 2b45e8
		       a + (- offset + is * lda) * COMPSIZE, lda, NULL, 0,
kusano 2b45e8
		       ipiv, 1, (void *)LASWP_PLUS, args -> nthreads);
kusano 2b45e8
    
kusano 2b45e8
    is += bk;
kusano 2b45e8
  }
kusano 2b45e8
  
kusano 2b45e8
  return info;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
#else
kusano 2b45e8
kusano 2b45e8
blasint CNAME(blas_arg_t *args, BLASLONG *range_m, BLASLONG *range_n, FLOAT *sa, FLOAT *sb, BLASLONG myid) {
kusano 2b45e8
kusano 2b45e8
  BLASLONG m, n, mn, lda, offset;
kusano 2b45e8
  BLASLONG i, is, bk, init_bk, next_bk, range_n_new[2];
kusano 2b45e8
  blasint *ipiv, iinfo, info;
kusano 2b45e8
  int mode;
kusano 2b45e8
  blas_arg_t newarg;
kusano 2b45e8
  FLOAT *a, *sbb;
kusano 2b45e8
  FLOAT dummyalpha[2] = {ZERO, ZERO};
kusano 2b45e8
kusano 2b45e8
  blas_queue_t queue[MAX_CPU_NUMBER];
kusano 2b45e8
  BLASLONG range[MAX_CPU_NUMBER + 1];
kusano 2b45e8
kusano 2b45e8
  BLASLONG width, nn, num_cpu;
kusano 2b45e8
kusano 2b45e8
  volatile BLASLONG flag[MAX_CPU_NUMBER * CACHE_LINE_SIZE] __attribute__((aligned(128)));
kusano 2b45e8
kusano 2b45e8
#ifndef COMPLEX
kusano 2b45e8
#ifdef XDOUBLE
kusano 2b45e8
  mode  =  BLAS_XDOUBLE | BLAS_REAL;
kusano 2b45e8
#elif defined(DOUBLE)
kusano 2b45e8
  mode  =  BLAS_DOUBLE  | BLAS_REAL;
kusano 2b45e8
#else
kusano 2b45e8
  mode  =  BLAS_SINGLE  | BLAS_REAL;
kusano 2b45e8
#endif  
kusano 2b45e8
#else
kusano 2b45e8
#ifdef XDOUBLE
kusano 2b45e8
  mode  =  BLAS_XDOUBLE | BLAS_COMPLEX;
kusano 2b45e8
#elif defined(DOUBLE)
kusano 2b45e8
  mode  =  BLAS_DOUBLE  | BLAS_COMPLEX;
kusano 2b45e8
#else
kusano 2b45e8
  mode  =  BLAS_SINGLE  | BLAS_COMPLEX;
kusano 2b45e8
#endif  
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
  m    = args -> m;
kusano 2b45e8
  n    = args -> n;
kusano 2b45e8
  a    = (FLOAT *)args -> a;
kusano 2b45e8
  lda  = args -> lda;
kusano 2b45e8
  ipiv = (blasint *)args -> c;
kusano 2b45e8
  offset = 0;
kusano 2b45e8
kusano 2b45e8
  if (range_n) {
kusano 2b45e8
    m     -= range_n[0];
kusano 2b45e8
    n      = range_n[1] - range_n[0];
kusano 2b45e8
    offset = range_n[0];
kusano 2b45e8
    a     += range_n[0] * (lda + 1) * COMPSIZE;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  if (m <= 0 || n <= 0) return 0;
kusano 2b45e8
  
kusano 2b45e8
  newarg.c   = ipiv;
kusano 2b45e8
  newarg.lda = lda;
kusano 2b45e8
  newarg.common = NULL;
kusano 2b45e8
  newarg.nthreads = args -> nthreads;
kusano 2b45e8
kusano 2b45e8
  mn = MIN(m, n);
kusano 2b45e8
kusano 2b45e8
  init_bk = (mn / 2 + GEMM_UNROLL_N - 1) & ~(GEMM_UNROLL_N - 1);
kusano 2b45e8
  if (init_bk > GEMM_Q) init_bk = GEMM_Q;
kusano 2b45e8
kusano 2b45e8
  if (init_bk <= GEMM_UNROLL_N) {
kusano 2b45e8
    info = GETF2(args, NULL, range_n, sa, sb, 0);
kusano 2b45e8
    return info;
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  width = FORMULA1(m, n, 0, init_bk, args -> nthreads);
kusano 2b45e8
  width = (width + GEMM_UNROLL_N - 1) & ~(GEMM_UNROLL_N - 1);
kusano 2b45e8
  if (width > n - init_bk) width = n - init_bk;
kusano 2b45e8
kusano 2b45e8
  if (width < init_bk) {
kusano 2b45e8
    long temp;
kusano 2b45e8
kusano 2b45e8
    temp = FORMULA2(m, n, 0, init_bk, args -> nthreads);
kusano 2b45e8
    temp = (temp + GEMM_UNROLL_N - 1) & ~(GEMM_UNROLL_N - 1);
kusano 2b45e8
kusano 2b45e8
    if (temp < GEMM_UNROLL_N) temp = GEMM_UNROLL_N;
kusano 2b45e8
    if (temp < init_bk) init_bk = temp;
kusano 2b45e8
kusano 2b45e8
  }
kusano 2b45e8
kusano 2b45e8
  next_bk = init_bk;
kusano 2b45e8
  bk      = init_bk;
kusano 2b45e8
kusano 2b45e8
  range_n_new[0] = offset;
kusano 2b45e8
  range_n_new[1] = offset + bk;
kusano 2b45e8
  
kusano 2b45e8
  info   = CNAME(args, NULL, range_n_new, sa, sb, 0);
kusano 2b45e8
  
kusano 2b45e8
  TRSM_ILTCOPY(bk, bk, a, lda, 0, sb);
kusano 2b45e8
kusano 2b45e8
  is = 0;
kusano 2b45e8
  num_cpu = 0;
kusano 2b45e8
kusano 2b45e8
  sbb = (FLOAT *)((((long)(sb + GEMM_PQ * GEMM_PQ * COMPSIZE) + GEMM_ALIGN) & ~GEMM_ALIGN) + GEMM_OFFSET_B);
kusano 2b45e8
kusano 2b45e8
  while (is < mn) {
kusano 2b45e8
kusano 2b45e8
    width  = FORMULA1(m, n, is, bk, args -> nthreads);
kusano 2b45e8
    width = (width + GEMM_UNROLL_N - 1) & ~(GEMM_UNROLL_N - 1);
kusano 2b45e8
    
kusano 2b45e8
    if (width < bk) {
kusano 2b45e8
kusano 2b45e8
      next_bk = FORMULA2(m, n, is, bk, args -> nthreads);
kusano 2b45e8
      next_bk = (next_bk + GEMM_UNROLL_N - 1) & ~(GEMM_UNROLL_N - 1);
kusano 2b45e8
kusano 2b45e8
      if (next_bk > bk) next_bk = bk;
kusano 2b45e8
#if 0
kusano 2b45e8
      if (next_bk < GEMM_UNROLL_N) next_bk = MIN(GEMM_UNROLL_N, mn - bk - is);
kusano 2b45e8
#else
kusano 2b45e8
      if (next_bk < GEMM_UNROLL_N) next_bk = MAX(GEMM_UNROLL_N, mn - bk - is);
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
      width = next_bk;
kusano 2b45e8
    }
kusano 2b45e8
    
kusano 2b45e8
    if (width > mn - is - bk) {
kusano 2b45e8
      next_bk = mn - is - bk;
kusano 2b45e8
      width   = next_bk;
kusano 2b45e8
    }
kusano 2b45e8
kusano 2b45e8
    nn = n - bk - is;
kusano 2b45e8
    if (width > nn) width = nn;
kusano 2b45e8
kusano 2b45e8
    if (num_cpu > 1)  exec_blas_async_wait(num_cpu - 1, &queue[1]);
kusano 2b45e8
kusano 2b45e8
    range[0] = 0;
kusano 2b45e8
    range[1] = width;
kusano 2b45e8
    
kusano 2b45e8
    num_cpu = 1;
kusano 2b45e8
    nn -= width;
kusano 2b45e8
    
kusano 2b45e8
    newarg.a   = sb;
kusano 2b45e8
    newarg.b   = a + (is + is * lda) * COMPSIZE;
kusano 2b45e8
    newarg.d   = (void *)flag;
kusano 2b45e8
    newarg.m   = m - bk - is;
kusano 2b45e8
    newarg.n   = n - bk - is;
kusano 2b45e8
    newarg.k   = bk;
kusano 2b45e8
    newarg.ldb = is + offset;
kusano 2b45e8
    
kusano 2b45e8
    while (nn > 0){
kusano 2b45e8
      
kusano 2b45e8
      width  = blas_quickdivide(nn + args -> nthreads - num_cpu, args -> nthreads - num_cpu);
kusano 2b45e8
      
kusano 2b45e8
      nn -= width;
kusano 2b45e8
      if (nn < 0) width = width + nn;
kusano 2b45e8
      
kusano 2b45e8
      range[num_cpu + 1] = range[num_cpu] + width;
kusano 2b45e8
      
kusano 2b45e8
      queue[num_cpu].mode    = mode;
kusano 2b45e8
      //queue[num_cpu].routine = inner_advanced_thread;
kusano 2b45e8
      queue[num_cpu].routine = (void *)inner_basic_thread;
kusano 2b45e8
      queue[num_cpu].args    = &newarg;
kusano 2b45e8
      queue[num_cpu].range_m = NULL;
kusano 2b45e8
      queue[num_cpu].range_n = &range[num_cpu];
kusano 2b45e8
      queue[num_cpu].sa      = NULL;
kusano 2b45e8
      queue[num_cpu].sb      = NULL;
kusano 2b45e8
      queue[num_cpu].next    = &queue[num_cpu + 1];
kusano 2b45e8
      flag[num_cpu * CACHE_LINE_SIZE] = 1;
kusano 2b45e8
kusano 2b45e8
      num_cpu ++;
kusano 2b45e8
    }
kusano 2b45e8
    
kusano 2b45e8
    queue[num_cpu - 1].next = NULL;
kusano 2b45e8
kusano 2b45e8
    is += bk;
kusano 2b45e8
    
kusano 2b45e8
    bk = n - is;
kusano 2b45e8
    if (bk > next_bk) bk = next_bk;
kusano 2b45e8
    
kusano 2b45e8
    range_n_new[0] = offset + is;
kusano 2b45e8
    range_n_new[1] = offset + is + bk;
kusano 2b45e8
    
kusano 2b45e8
    if (num_cpu > 1) {
kusano 2b45e8
kusano 2b45e8
      exec_blas_async(1, &queue[1]);
kusano 2b45e8
    
kusano 2b45e8
#if 0
kusano 2b45e8
      inner_basic_thread(&newarg, NULL, &range[0], sa, sbb, 0);
kusano 2b45e8
kusano 2b45e8
      iinfo = GETRF_SINGLE(args, NULL, range_n_new, sa, sbb, 0);
kusano 2b45e8
#else
kusano 2b45e8
kusano 2b45e8
      if (range[1] >= bk * 4) {
kusano 2b45e8
kusano 2b45e8
	BLASLONG myrange[2];
kusano 2b45e8
kusano 2b45e8
	myrange[0] = 0;
kusano 2b45e8
	myrange[1] = bk;
kusano 2b45e8
kusano 2b45e8
	inner_basic_thread(&newarg, NULL, &myrange[0], sa, sbb, -1);
kusano 2b45e8
kusano 2b45e8
	iinfo = GETRF_SINGLE(args, NULL, range_n_new, sa, sbb, 0);
kusano 2b45e8
kusano 2b45e8
	myrange[0] = bk;
kusano 2b45e8
	myrange[1] = range[1];
kusano 2b45e8
kusano 2b45e8
	inner_basic_thread(&newarg, NULL, &myrange[0], sa, sbb, -1);
kusano 2b45e8
kusano 2b45e8
      } else {
kusano 2b45e8
kusano 2b45e8
	inner_basic_thread(&newarg, NULL, &range[0], sa, sbb, -1);
kusano 2b45e8
kusano 2b45e8
	iinfo = GETRF_SINGLE(args, NULL, range_n_new, sa, sbb, 0);
kusano 2b45e8
      }
kusano 2b45e8
kusano 2b45e8
#endif
kusano 2b45e8
kusano 2b45e8
      for (i = 1; i < num_cpu; i ++) while (flag[i * CACHE_LINE_SIZE]) {};
kusano 2b45e8
      
kusano 2b45e8
      TRSM_ILTCOPY(bk, bk, a + (is +  is * lda) * COMPSIZE, lda, 0, sb);
kusano 2b45e8
      
kusano 2b45e8
    } else {
kusano 2b45e8
kusano 2b45e8
      inner_basic_thread(&newarg, NULL, &range[0], sa, sbb, -1);
kusano 2b45e8
      
kusano 2b45e8
      iinfo = GETRF_SINGLE(args, NULL, range_n_new, sa, sbb, 0);
kusano 2b45e8
    }
kusano 2b45e8
kusano 2b45e8
      if (iinfo && !info) info = iinfo + is;
kusano 2b45e8
      
kusano 2b45e8
  }
kusano 2b45e8
  
kusano 2b45e8
  next_bk = init_bk;
kusano 2b45e8
  bk      = init_bk;
kusano 2b45e8
  
kusano 2b45e8
  is = 0;
kusano 2b45e8
  
kusano 2b45e8
  while (is < mn) {
kusano 2b45e8
    
kusano 2b45e8
    bk = mn - is;
kusano 2b45e8
    if (bk > next_bk) bk = next_bk;
kusano 2b45e8
    
kusano 2b45e8
    width  = FORMULA1(m, n, is, bk, args -> nthreads);
kusano 2b45e8
    width = (width + GEMM_UNROLL_N - 1) & ~(GEMM_UNROLL_N - 1);
kusano 2b45e8
kusano 2b45e8
    if (width < bk) {
kusano 2b45e8
      next_bk = FORMULA2(m, n, is, bk, args -> nthreads);
kusano 2b45e8
      next_bk = (next_bk + GEMM_UNROLL_N - 1) & ~(GEMM_UNROLL_N - 1);
kusano 2b45e8
kusano 2b45e8
      if (next_bk > bk) next_bk = bk;
kusano 2b45e8
#if 0
kusano 2b45e8
      if (next_bk < GEMM_UNROLL_N) next_bk = MIN(GEMM_UNROLL_N, mn - bk - is);
kusano 2b45e8
#else
kusano 2b45e8
      if (next_bk < GEMM_UNROLL_N) next_bk = MAX(GEMM_UNROLL_N, mn - bk - is);
kusano 2b45e8
#endif
kusano 2b45e8
    }
kusano 2b45e8
kusano 2b45e8
    if (width > mn - is - bk) {
kusano 2b45e8
      next_bk = mn - is - bk;
kusano 2b45e8
      width   = next_bk;
kusano 2b45e8
    }
kusano 2b45e8
kusano 2b45e8
    blas_level1_thread(mode, bk, is + bk + offset + 1, mn + offset, (void *)dummyalpha, 
kusano 2b45e8
		       a + (- offset + is * lda) * COMPSIZE, lda, NULL, 0,
kusano 2b45e8
		       ipiv, 1, (void *)LASWP_PLUS, args -> nthreads);
kusano 2b45e8
    
kusano 2b45e8
    is += bk;
kusano 2b45e8
  }
kusano 2b45e8
  
kusano 2b45e8
  return info;
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
#endif
kusano 2b45e8