initproc.c 3.15 KB
Newer Older
Tilman Steinweg's avatar
Tilman Steinweg committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*------------------------------------------------------------------------
 * Copyright (C) 2011 For the list of authors, see file AUTHORS.
 *
 * This file is part of SOFI2D.
 * 
 * SOFI2D 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, version 2.0 of the License only.
 * 
 * SOFI2D 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 SOFI2D. See file COPYING and/or 
  * <http://www.gnu.org/licenses/gpl-2.0.html>.
--------------------------------------------------------------------------*/
/* -------------------------------------------------------------
 * This is function initproc.
 * Dividing the 2-D FD grid into domains and assigning the
 * PEs to these domains,
 *
 * -------------------------------------------------------------*/

#include "fd.h"

void initproc(void)	{

	extern int NX, NY, IENDX, IENDY, POS[3], INDEX[5];
	extern int NP, NPROC, NPROCX, NPROCY, MYID;
	extern FILE *FP;
	
	if ((NPROC != NP)  && (MYID==0)) {
		fprintf(FP,"You specified NPROC =  %d (in parameter file) and NP = %d (command line) \n",NPROC,NP);
Tilman Steinweg's avatar
Tilman Steinweg committed
36
		declare_error("NP and NPROC differ !");
Tilman Steinweg's avatar
Tilman Steinweg committed
37
38
39
	}

	/*if (NPROC != NP)
Tilman Steinweg's avatar
Tilman Steinweg committed
40
		declare_error("Number of processors specified in the parameter file \n and at command line (NP) differ !");*/
Tilman Steinweg's avatar
Tilman Steinweg committed
41
42
43
44
45
46
47
48
49


	/*C-- determine the length of the subarray on this processor*/
	IENDX = NX/NPROCX;
	IENDY = NY/NPROCY;

	/* POS(1) indicates x POSition of the processor in the 
		     logical 3D processor array*/
	if ((NX%NPROCX)>0)
Tilman Steinweg's avatar
Tilman Steinweg committed
50
		declare_error(" NX%NPROX (modulus) must be zero  !");
Tilman Steinweg's avatar
Tilman Steinweg committed
51
	if ((NY%NPROCY)>0)
Tilman Steinweg's avatar
Tilman Steinweg committed
52
		declare_error(" NY%NPROY (modulus) must be zero  !");
Tilman Steinweg's avatar
Tilman Steinweg committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86


	if (MYID==0){
		fprintf(FP,"\n **Message from initprocs (printed by PE %d):\n",MYID);
		fprintf(FP," Size of subarrays in gridpoints:\n");
		fprintf(FP," IENDX= %d\n",IENDX);
		fprintf(FP," IENDY (vertical) = %d\n",IENDY);
	}



	/*---------------   index is indicating neighbouring processes	--------------------*/
	INDEX[1]=MYID-1;  		 /* left	*/
	INDEX[2]=MYID+1;  		 /* right	*/
	INDEX[3]=MYID-NPROCX;  		 /* upper	*/
	INDEX[4]=MYID+NPROCX;  		 /* lower	*/
	
	/*---------------   POS indicates the processor location in the 3D logical processor array	---------*/
	POS[1] = MYID % NPROCX;			/*  x coordinate */
	POS[2] = (MYID/NPROCX); 	/*  y coordinate */

	if (POS[1] == 0)        INDEX[1]=INDEX[1] + NPROCX;        	  
	if (POS[1] == NPROCX-1) INDEX[2]=INDEX[2] - NPROCX;          	 
	if (POS[2] == 0)        INDEX[3]=(NPROCX*NPROCY)+MYID-NPROCX; 	 
	if (POS[2] == NPROCY-1) INDEX[4]=MYID+NPROCX-(NPROCX*NPROCY);	 

	fprintf(FP,"\n");
	fprintf(FP," **Message from initprocs (written by PE %d):\n",MYID);
	fprintf(FP," Processor locations in the 2D logical processor array\n");
	fprintf(FP," MYID \t POS(1):left,right \t POS(2): top, bottom\n");
	
	fprintf(FP," %d \t\t %d: %d,%d \t\t %d: %d,%d \n",
	    MYID,POS[1],INDEX[1],INDEX[2], POS[2], INDEX[3],INDEX[4]);
}