ejr / matchpres (public) (License: BSD) (since 2018-08-29) (hash sha1)
Ye olde thesis code implementing an auction-based weighted bipartite matching algorithm over MPI.

/seqauction.c (f5eed2c9d95ff09dde048b97e8d11e14253c8bf1) (6598 bytes) (mode 100644) (type blob)

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <float.h>
#include <math.h>

#include <assert.h>

#if defined(HAVE_CALLGRIND)
#include <valgrind/callgrind.h>
#else
#define CALLGRIND_START_INSTRUMENTATION() do { } while (0)
#define CALLGRIND_STOP_INSTRUMENTATION() do { } while (0)
#define CALLGRIND_DUMP_STATS() do { } while (0)
#define CALLGRIND_ZERO_STATS() do { } while (0)
#define CALLGRIND_TOGGLE_COLLECT() do { } while (0)
#endif

#include "smut.h"
#include "timer.h"
#include "auction.h"

#if !defined(HAVE_RESTRICT)
#define restrict
#endif

static int icntl[10];
void mc64ad_ (int* JOB,
	      int* N,
	      int* NE,
	      int* IP,
	      int* IRN,
	      double* A,
	      int* NUM,
	      int* CPERM,
	      int* LIW,
	      int* IW,
	      int* LDW,
	      double* DW,
	      int* ICNTL,
	      int* INFO);

void mc64wd_ (int* n, int* ne, int* ip, int* irn, double* a,
	      int* iperm, int* num, int* jperm, int* out,
	      int* pr, int* q, int* L, double* U, double* D);

int
main (int argc, char **argv)
{
  FILE *f, *fout = NULL;
  int err;

  struct spcsr_t A;

  double mu_min;

  double *R, *C;
  double *expint;

  int *match, *invmatch;
  double *price;

  int errflg, i, j;
  double p, d;
  volatile double auction_primal = 0.0, mc64_primal = 0.0;
  /* gcc-3.4 compiler bug?  ap becomes zero after calling mc64
     with optimization */

  struct Timer timer;

  assert(sizeof(int) == 4);

  if (argc <= 1) {
    printf("No files\n");
    return -1;
  }

  f = fopen(argv[1], "rb");
  if (!f) {
    perror("Error opening file: ");
    return -1;
  }

  if (argc > 2) {
    fout = fopen (argv[2], "wb");
  }

  err = spcsr_load_binfile (f, &A);
  if (err) {
    printf ("Error reading: %d\n", err);
    return -1;
  }
  fclose(f);

  R = malloc (A.nr * sizeof(double));
  C = malloc (A.nc * sizeof(double));
  expint = malloc (A.nent * sizeof(double));

  match = malloc (A.nc * sizeof(int));
  invmatch = malloc (A.nr * sizeof(int));
  memset (match, -1, A.nc * sizeof(int));
  memset (invmatch, -1, A.nr * sizeof(int));
  price = calloc (A.nc, sizeof(double));

  printf ("nr = %d nc = %d nent = %d\n", A.nr, A.nc, A.nent);

#if 0
  spcsr_lascaling (&A, R, C);
  spcsr_apply_scaling (&A, R, C);
#elif 1
  spcsr_lascale (&A, R, C);
#endif

#if 1
  auction_toexpint (&A, expint);
#else
  auction_toexp (&A, expint);
#endif
  auction_shift (&A, expint);

  {
    int k;
    double mx = -HUGE_VAL, mn = HUGE_VAL;
    for (k = 0; k < A.nent; ++k) {
      double e = expint[k];
      if (e < mn) mn = e;
      if (e > mx) mx = e;
    }
    printf ("expint max: %g , min %g\n", mx, mn);
  }

  cacheblast();

  mu_min = 1.0 / A.nr;
  /* be approximate */
  /*mu_min = 1.0;*/
  /*mu_min = 100.0 / A.nr;*/

#if 0
  {
    int n_unmatched;
    double mu_min;
    double p, d;

    initialize_timer (&timer);
    start_timer (&timer);
    n_unmatched = auction_simple (A, expint, match, price, mu_min);
    stop_timer (&timer);
    auction_eval_primal_mdual (A, expint, match, price, &p, &d);
    printf ("* Primal: %20g\n* Dual: %20g\n* Time: %20g\n", p, d,
	    timer_duration(timer));
    a_printstats ();
  }
#endif

  cacheblast();

  memset (match, -1, A.nc * sizeof(int));
  memset (price, 0, A.nc * sizeof(double));
  CALLGRIND_START_INSTRUMENTATION();
  initialize_timer (&timer);
  start_timer (&timer);
  errflg = auction_scaling (A, expint, match, price, mu_min, 0);
  stop_timer (&timer);
  if (errflg)
    fprintf (stderr, "Errflg: %d\n", errflg);


  auction_eval_primal_mdual (A, expint, match, price, &auction_primal, &d);
  printf ("Primal: %20g\nDual: %20g\nTime: %20g\nmu_min: %20g\n",
	  auction_primal, d, timer_duration(timer), mu_min);

  a_printstats();

  {
    int i, j;
    for (j = 0; j < A.nc; ++j) {
      if (match[j] < 0) printf("column %d is unmatched\n", j);
      if (match[j] >= A.nr) printf("column %d's match out of range (%d/%d)\n",
				   j, match[j], A.nr);
    }
    for (i = 0; i < A.nr; ++i) {
      int k;
      int found_match = 0;
      for (k = A.rowoff[i]; k < A.rowoff[i+1]; ++k) {
	const int j = A.colind[k];
	if (i == match[j]) ++found_match;
      }
      if (!found_match)	printf ("row %d is unmatched\n", i);
      if (found_match > 1) printf ("row %d is multiply matched\n", i);
    }
  }

  if (fout) {
    int tag = 1;
    fwrite (&tag, sizeof(int), 1, fout);
    fwrite (&A.nc, sizeof(int), 1, fout);
    fwrite (match, sizeof(int), A.nc, fout);
  }

#if 0
  cacheblast();

  {
    int n_unmatched;
    double mu_min;
    double p, d;

    initialize_timer (&timer);
    start_timer (&timer);
    n_unmatched = auction_scaling_cache (A, expint, match, price, mu_min);
    stop_timer (&timer);
    auction_eval_primal_mdual (A, expint, match, price, &p, &d);
    printf ("_ Primal: %20g\n_ Dual: %20g\n_ Time: %20g\n", p, d,
	    timer_duration(timer));
    a_printstats ();
  }
#endif

  CALLGRIND_STOP_INSTRUMENTATION();

  cacheblast();

  /* mc64 */
  {
    int job = 4; /* sum of diag, already log scale */
    int num_on_diag = 0;
    int liw;
    int *iw;
    int ldw;
    double *dw;
    int info = 0;

    int i, k;

    for (i = 0; i <= A.nr; ++i)
      ++A.rowoff[i];
    for (k = 0; k < A.nent; ++k)
      ++A.colind[k];

    initialize_timer (&timer);
    start_timer (&timer);
    liw = 5 * A.nr;
    iw = malloc (liw * sizeof(int));
    ldw = 2 * A.nr + A.nent;
    dw = malloc (ldw * sizeof(double));
    memset (icntl, 0, 10 * sizeof(int));
    icntl[0] = 6; icntl[1] = 6; icntl[2] = -1;
#if !defined(NDEBUG)
    icntl[3] = 0;
#else
    icntl[3] = -1;
#endif
    mc64ad_ (&job, &A.nr, &A.nent, A.rowoff, A.colind, expint,
	     &num_on_diag, invmatch, &liw, iw, &ldw, dw, icntl,
	     &info);
    free (iw);
    free (dw);
    stop_timer (&timer);

    for (i = 0; i < A.nr; ++i) --invmatch[i];
    for (i = 0; i <= A.nr; ++i) --A.rowoff[i];
    for (k = 0; k < A.nent; ++k)
      --A.colind[k];

  }

  for (i = 0; i < A.nr; ++i) {
    if (invmatch[i] < 0) printf("mc64: row %d is unmatched\n", i);
  }

  memset (match, -1, A.nc * sizeof(int));
  for (i = 0; i < A.nr; ++i) {
    const int j = invmatch[i];
    match[j] = i;
  }
  for (j = 0; j < A.nc; ++j) {
    if (match[j] < 0) printf("mc64: col %d is unmatched\n", j);
  }
  auction_eval_primal_mdual (A, expint, invmatch, price, &mc64_primal, &d);
  printf ("mc64 Primal: %20g\nmc64 Time: %20g\n", mc64_primal,
	  timer_duration(timer));
  printf ("  primal diff: %20g\n", auction_primal - mc64_primal);

  free (price);
  free (invmatch);
  free (match);
  free (expint);
  free (R);
  free (C);
  spcsr_free (&A);
  return 0;
}


Mode Type Size Ref File
100644 blob 713 399ea10dab40d3201aa0e9f6eb62c51b099d970f Make.ejr-citris
100644 blob 486 dcf1d527e538d4ca5ebe2951800b3a3b70474872 Make.ejr-home-gcc
100644 blob 175 3592281b201df903859285e50c914c2f8b618b4b Make.seaborg
100644 blob 3307 f715c36bf2ae4a4f455cc7177350dba21c21c1ca Makefile
100644 blob 42677 f3dd0961175560130247e5c2288f6f5164790456 auction.c
100644 blob 3016 a574b362b4d966599d6720ca0439d385a92084e1 auction.h
100644 blob 302 6995992eb49553aadebe4dddd1a3a74eacf4f332 cacheblast.c
100644 blob 3386 2b76fb3e0a5bb941d13e1ff6f4b2cf152af929e3 colcomp.c
100644 blob 582 3afbfafab8b4b83786e48a66cf20df7eb1feaf8c convmats.m
100644 blob 2189 fba47c6f3908699da08dfac9469d296af62dc234 lsame.c
100644 blob 5244 cb06aa63b1f49d49da789a8feeaf3a19a3155b36 matchmtx.c
040000 tree - 3fcccf0fc51adf74ea4fc6c501e65306ada6fdd1 mc64
040000 tree - c1a5dab1b4b8999153b6d04dae4624af7038dcec mlb
100644 blob 6344 74992c1d4736ff84fdcdcf2b1be7f4eaf7de3b63 mpitransposebin.c
100644 blob 6351 f4beee0452662b6f5bc6d79b839faec02ce6802e mpitransposebin_root.c
100644 blob 1092028 89dad69d7b2de3e183bfc343e98e1943a9d34e16 orani678.bin
100644 blob 19048 d3d22a8af49f546fd09aaded2d7256d312d3b838 parauction.c
100644 blob 18896 7134aa840f527455d5bf617ee9e54c91ae2161d7 parauction_allgather.c
100644 blob 14315 4f475a8317c54d70c33d7d3744b7c47943d26883 parauction_allreduce.c
100644 blob 18564 37c1e950e97bd0fb9aafec2db7fdeeaf9339a09b parauction_root.c
100644 blob 1154 2fc93276b1723c805e82d0e9eb4781184bfcca2e readbin.c
100644 blob 864 5f791479f6982f22101a5094efb0fa0947b54310 readbin.m
100644 blob 696 6151ee6074636c5bdd0d5f34ee4d9b0c76e0501d readmatch.m
100644 blob 1182 8b0bfcc7b6bac0c7f701ae317cbeeff5feec512a redist1.c
100644 blob 1412 4dae58f785498844725f72c26f70621b9287ad1e redist2.c
100644 blob 3002 f41bc38e57d9c613a6426045d0ea7ac22bd339de redist3.c
100644 blob 2903 857ee46542a70759476e2a7437e900c32f12001c redist4.c
100644 blob 6598 f5eed2c9d95ff09dde048b97e8d11e14253c8bf1 seqauction.c
100644 blob 15392 9fac5aac4170c6cd7d9c2327911a531ea7950dad smut.c
100644 blob 2338 06f2519a40af810ecfaa5e250459109aed6ee642 smut.h
100644 blob 13779 5ac297a1fcfeeadc5d107470f1fcf6215c9521bc stripe_auction.c
100644 blob 1771 f709206b1e373cf8c7a3c3d3fb702b4bae72d435 stripe_auction.h
100644 blob 39548 5389671d60b8e2ddd1f9360551377d35c8ccdbd2 stripesmut.c
100644 blob 1402 075d97c492be1e6546e24d4a330566981616ac0e stripesmut.h
100644 blob 627 9909b624922275b657ab5d66774f4c40c8beb760 timer.c
100644 blob 405 46eb6c267780afd6b1ee7816a42332cdf79d2683 timer.h
100644 blob 942 d254d606053141bc0a6ffdf714a436980900c028 transposebin.c
100644 blob 697 3728ae018c10cf4308bce2388b75bafe4be41942 writebin.c
100644 blob 940 9643894cce30bc371dc4549a1fc1af4fa3dde2ac writebin.m
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/ejr/matchpres

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/ejr/matchpres

Clone this repository using git:
git clone git://git.rocketgit.com/user/ejr/matchpres

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main