Next version of JABA
[jabaws.git] / binaries / src / fasta34 / hostacc.c
1
2 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
3    U. of Virginia */
4
5 /* $Name: fa_34_26_5 $ - $Id: hostacc.c,v 1.7 2006/04/12 18:00:02 wrp Exp $ */
6
7 /* Concurrent read version */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <sys/time.h>
12
13 #ifdef PVM_SRC
14 #include "pvm3.h"
15 #endif
16 #ifdef MPI_SRC
17 #include "mpi.h"
18 #endif
19
20 #include "msg.h"
21
22 #define XTERNAL
23 #include "uascii.h"
24 #include "upam.h"
25 #undef XTERNAL
26
27 extern char prog_name[];
28
29 extern int nnodes;
30 #ifdef PVM_SRC
31 extern int pinums[];
32 #endif
33
34
35 #ifdef PVM_SRC
36 int tidtonode(tid)
37      int tid;
38 {
39   int i;
40   for (i=FIRSTNODE; i< nnodes; i++) if (tid==pinums[i]) return i;
41   return -1;
42 }
43 #endif
44
45 /* rand_nodes selects nnodes at random from max_nodes */
46
47 void
48 rand_nodes(int *node_map, int nnodes, int max_nodes)
49 {
50   int node_used[MAXNOD];
51   int i, j;
52   struct timeval tv;
53
54   gettimeofday(&tv,NULL);
55   SRAND(tv.tv_usec);
56
57   for (i=0; i<max_nodes; i++) node_used[i]=0;
58
59   if (nnodes < (max_nodes+1)/2) {
60     for (i=0; i<nnodes; ) {
61       j = RAND()%max_nodes;
62       if (node_used[j]) continue;
63       else {
64         node_map[i++]=j;
65         node_used[j]=1;
66       }
67     }
68   }
69   else {
70     for (i=0; i<(max_nodes-nnodes); ) {
71       j = RAND()%max_nodes;
72       if (node_used[j]) continue;
73       else {
74         node_used[j]=1;
75         i++;
76       }
77     }
78     for (i=j=0; i<nnodes; j++)
79       if (node_used[j]) continue;
80       else node_map[i++]=j;
81   }
82 /*  for (i=0; i<nnodes; i++) fprintf(stderr,"%2d %2d\n",i,node_map[i]); */
83 }