/*
*===============================================================================
*
* d/wilson_d500/dirac.c 
*
*-------------------------------------------------------------------------------
*
* Copyright (C) 2006 Thomas Streuer 
*
* This file is part of BQCD -- Berlin Quantum ChromoDynamics program
*
* BQCD is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* BQCD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with BQCD.  If not, see <http:*www.gnu.org/licenses/>.
*
*-------------------------------------------------------------------------------
*/
#include <stdio.h>
#include <errno.h>
#include <mpi.h>
#include "neighb.h"

extern void a_dirac(double*, double*, double*, int, double);
extern void a_dirac_dg(double*, double*, double*, int, double);
extern int my_rank;
extern int test_stat(const void* stat_addr, int byte);

/* int recv_fifo_stat(int f, int mu) */
/* { */
/*   return test_stat(recv_stat_addr[f][mu], recv_stat_byte_offs[f][mu]); */
/* } */

/* int send_fifo_stat(int f, int mu) */
/* { */
/*   return test_stat(send_stat_addr[f][mu], send_stat_byte_offs[f][mu]); */
/* } */


/* void first() */
/* { */
/*   static int f=1; */
/*   if (f) */
/*   { */
/*     f=0; */
/*     printf("[%i] first: s %2i %2i %2i   %2i %2i %2i\tr %2i %2i %2i   %2i %2i %2i\n", my_rank, */
/* 	   send_fifo_stat(0, 0), send_fifo_stat(0, 1), send_fifo_stat(0, 2), */
/* 	   send_fifo_stat(1, 0), send_fifo_stat(1, 1), send_fifo_stat(1, 2), */
/* 	   recv_fifo_stat(0, 0), recv_fifo_stat(0, 1), recv_fifo_stat(0, 2), */
/* 	   recv_fifo_stat(1, 0), recv_fifo_stat(1, 1), recv_fifo_stat(1, 2)); */
/*     fflush(stdout); */
/*     MPI_Barrier(MPI_COMM_WORLD); */
/*   } */

/* } */

/* void lastt() */
/* { */
/*   static int f=1; */
/*   if (f) */
/*   { */
/*     f=0; */
/*     MPI_Barrier(MPI_COMM_WORLD); */
/*     printf("[%i] larst: s %2i %2i %2i   %2i %2i %2i\tr %2i %2i %2i   %2i %2i %2i\n", my_rank, */
/* 	   send_fifo_stat(0, 0), send_fifo_stat(0, 1), send_fifo_stat(0, 2), */
/* 	   send_fifo_stat(1, 0), send_fifo_stat(1, 1), send_fifo_stat(1, 2), */
/* 	   recv_fifo_stat(0, 0), recv_fifo_stat(0, 1), recv_fifo_stat(0, 2), */
/* 	   recv_fifo_stat(1, 0), recv_fifo_stat(1, 1), recv_fifo_stat(1, 2)); */
/*     fflush(stdout); */
/*     MPI_Barrier(MPI_COMM_WORLD); */
/*   } */

/* } */

void dirac(double* U, double* in, double* out, double* kappa, int* oe)
{
/*   first(); */
/*   if (my_rank==0) */
/*   printf(".");fflush(stdout); */
/*   static int ctr=0; */
/*   if (ctr==446) */
/*   { */
/*     char fn[200]; */
/*     sprintf(fn, "bq_input_%04i", my_rank); */
/*     FILE* f=fopen(fn, "w"); */
/*     fwrite(in, sizeof(double), 24*wilson_data.volh_tot, f); */
/*     fclose(f); */
/*     sprintf(fn, "bq_output_%04i", my_rank); */
/*     f=fopen(fn, "w"); */
/*     fwrite(out, sizeof(double), 24*wilson_data.volh_tot, f); */
/*     fclose(f); */
/*     sprintf(fn, "bq_U_%04i", my_rank); */
/*     f=fopen(fn, "w"); */
/*     fwrite(U, sizeof(double), 144*wilson_data.volh_tot, f); */
/*     fclose(f); */
/*   } */

/*   if (my_rank==0) */
/*   { */
/*     printf("[%i] D!! e/o: %i, ct %i\t", my_rank, *oe, ctr); */
/*     fflush(stdout); */
/*   } */
/*   if (ctr==446 && my_rank==0) */
/*   { */
/* /\*     sleep(10); *\/ */
/* /\*     abort(); *\/ */
/*   } */
/*   if (ctr>=0) */
/*     for (int i=0; i<12*wilson_data.volume; i++) */
/*       out[i]=in[i]; */
/*   else */


/*   int rstat=0; */
/*   for (int i=0; i<6; i++) */
/*     rstat+=test_stat(stat_addr, recv_stat_byte_offs[0][i]); */
/*   int sstat=0; */
/*   for (int i=0; i<6; i++) */
/*     sstat+=test_stat(stat_addr, send_stat_byte_offs[0][i]); */

/*   sleep(1); */
  a_dirac(U, in, out, *oe, *kappa);
/*   sleep(1); */
/*   if (my_rank==0) */
/*     printf("[%i] D done!! stat: %i\n", my_rank, ctr); */
/*   if (ctr++==0 && my_rank==0) */
/*   { */
/*     char fn[200]; */
/*     sprintf(fn, "my_output_%04i", my_rank);     */
/*     FILE* f=fopen(fn, "w"); */
/*     fwrite(out, sizeof(double), 24*wilson_data.volh_tot, f); */
/*     fclose(f); */
/*     printf("[%i] stat: %i %i\n", my_rank, wilson_data.test_data, ctr); */
/*   } */
/*   ctr++; */
/*   if (my_rank==0) */
/*   printf(">");fflush(stdout); */
}

void dirac_dag(double* U, double* in, double* out, double* kappa, int* oe)
{
/*   first(); */
/*   if (my_rank==0) */
/*   printf("-");fflush(stdout); */
/*   double* in_ptr=in; */



/*   double tmp[4]; */
/*   for (int i=0; i<3*wilson_data.volume; i++) */
/*   { */
/*     tmp[0]=in_ptr[0]; */
/*     tmp[1]=in_ptr[1]; */
/*     tmp[2]=in_ptr[2]; */
/*     tmp[3]=in_ptr[3]; */
/*     in_ptr[0]=in_ptr[4]; */
/*     in_ptr[1]=in_ptr[5]; */
/*     in_ptr[2]=in_ptr[6]; */
/*     in_ptr[3]=in_ptr[7]; */
/*     in_ptr[4]=tmp[0]; */
/*     in_ptr[5]=tmp[1]; */
/*     in_ptr[6]=tmp[2]; */
/*     in_ptr[7]=tmp[3]; */
/*     in_ptr+=8; */
/*   } */




/*   static int ctr=0; */
/*   if (my_rank==0) */
/*   { */
/*     printf("[%i] D-dg!! e/o: %i, ct %i\t", my_rank, *oe, ctr); */
/*     fflush(stdout); */
/*   } */
/*   if (ctr>=0) */
/*     for (int i=0; i<12*wilson_data.volume; i++) */
/*       out[i]=in[i]; */
/*   else */
/*   int rstat=0; */
/*   for (int i=0; i<6; i++) */
/*     rstat+=test_stat(stat_addr, recv_stat_byte_offs[0][i]); */
/*   int sstat=0; */
/*   for (int i=0; i<6; i++) */
/*     sstat+=test_stat(stat_addr, send_stat_byte_offs[0][i]); */
/*   sleep(1); */
  a_dirac_dg(U, in, out, *oe, *kappa);
/*   sleep(1); */
/*   if (my_rank==0) */
/*     printf("[%i] D-dg done!! stat: %i %i\n", my_rank, ctr, ctr); */
/*   ctr++; */


/*   in_ptr=out; */
/*   for (int i=0; i<3*wilson_data.volume; i++) */
/*   { */
/*     tmp[0]=in_ptr[0]; */
/*     tmp[1]=in_ptr[1]; */
/*     tmp[2]=in_ptr[2]; */
/*     tmp[3]=in_ptr[3]; */
/*     in_ptr[0]=in_ptr[4]; */
/*     in_ptr[1]=in_ptr[5]; */
/*     in_ptr[2]=in_ptr[6]; */
/*     in_ptr[3]=in_ptr[7]; */
/*     in_ptr[4]=tmp[0]; */
/*     in_ptr[5]=tmp[1]; */
/*     in_ptr[6]=tmp[2]; */
/*     in_ptr[7]=tmp[3]; */
/*     in_ptr+=8; */
/*   } */



/*   if (my_rank==0) */
/*   printf(">");fflush(stdout); */
}

