/* Konfiguration Eintragen des include-Verzeichnisses 32 Bit D:\Daten\MPICH2\include\ 64 Bit: C:\Program Files\Microsoft MPI\inc; Eintragen des lib-Verzeichnisses 32 Bit D:\Daten\MPICH2\lib\ 64 Bit C:\Program Files\Microsoft MPI\Lib\i386; Eintragen der MPI-Libray unter Linker-Register: 32 Bit: mpi.lib 64 Bit: msmpi.lib; */ // Aufgabe2.cpp : #include #include #include #include // div_t #include #include "stdafx.h" const int ROOT = 0; // Globale Variablen char *_Root_zellen=NULL; int _anzRows, _anzCols; char *_Lokal_zellen=NULL; // fuer die Testphase, wandelt nicht den Inhalt der Datei um // Man kann damit besser das Senden und Empfangen testen bool _bDebug = false; int readFile(int wahl) { int i, j, n; int offset; char sFile[200]; FILE *stream; char line[501]; strcpy_s(sFile,"life1.txt"); sFile[4] = (char) (wahl+48); printf("gewählte Datei: %s\n",sFile); stream = fopen(sFile, "r" ); if( stream == NULL ) { printf("Fehler beim Öffnen der Datei %s\n", sFile); return 1; } if( fgets( line, 500, stream ) == NULL){ printf("Fehler beim Lesen der ersten Zeile\n"); return 1; } n = sscanf(line,"%d",&_anzCols); // anzRows, anzCols; if (n==0) { printf("Fehler beim Lesen der Anzahl der Spalten\n"); return 1; } if( fgets( line, 500, stream ) == NULL){ printf("Fehler beim Lesen der zweiten Zeile\n"); return 1; } n = sscanf(line,"%d",&_anzRows); // anzRows, anzCols; if (n==0) { printf("Fehler beim Lesen der Anzahl der Zeilen\n"); return 1; } printf("anzRows:%d anzCols:%d\n",_anzRows,_anzCols); _Root_zellen = new char[_anzRows*_anzCols]; offset=0; for (i=0;i<_anzRows; i++) { if( fgets( line, 500, stream ) == NULL){ printf("Fehler beim Lesen der %d. Datenzeile\n",i); return 1; } // printf("x:%s\n",line); if (_bDebug) { // Fuer erste Tests line[0]=char(0x41+i); // warum bloss die 0x41 ? for (j=0; j<_anzCols; j++) { _Root_zellen[j+offset]=line[j]; } } else { for (j=0; j<_anzCols; j++) { if ( line[j]=='1' ) _Root_zellen[j+offset]='*'; else _Root_zellen[j+offset]=' '; } } offset+=_anzCols; } fclose( stream ); return 0; } // readFile // komplett void testPrintRoot(int loop) { int i; int offset; char line[5001]; offset=0; printf("\n\ntestausgabe: %d\n",loop); for (i=0;i<_anzRows; i++) { strncpy(line,&_Root_zellen[offset],_anzCols); line[_anzCols] = '\0'; printf("%s\n",line); offset+=_anzCols; } strncpy(line,_Root_zellen,_anzRows*_anzCols); line[_anzRows*_anzCols] = '\0'; // printf("%s\n",line); } // testPrintRoot // komplett void testPrintLokal(int Pid) { char line[501]; strncpy(line,_Lokal_zellen,_anzCols); line[_anzCols] = '\0'; printf("Pid: %d |%s|\n",Pid,line); } // testPrintLokal // komplett void testPrintTopBottom(int Pid,char *title, char *local) { char line[501]; strncpy(line,local,_anzCols); line[_anzCols] = '\0'; printf("Pid: %d |%s|%s|\n",Pid,title, line); } // testPrintLokal // hier fehlt etwas Code int main(int argc, char *argv[]) { int i, j, n, Pid; int wahl, wahltemp; int numprocs; int l_change; int root_change; if (MPI_Init(&argc, &argv)!=MPI_SUCCESS) { printf( "MPI_Init failed.\n"); MPI_Finalize(); return 1; } // Anzahl der Prozesse MPI_Comm_size(MPI_COMM_WORLD,&numprocs); if ( numprocs <2 ){ puts("Bitte mit mindestens mit zwei Prozesse starten"); MPI_Finalize(); return 1; } // meine eigene ID if ( MPI_Comm_rank(MPI_COMM_WORLD,&Pid) !=MPI_SUCCESS) { printf( "MPI_Comm_rank fehlerhaft\n"); MPI_Finalize(); return 1; } wahl=1; // defaultwert if (Pid == ROOT) { if (argc>1) { // puts(argv[0]); // Anzeige des Programmsnamens // n zeigt an, ob ein Wert konvertiuert werden konnte n=sscanf(argv[1], "%d",&wahltemp); if (n==1) { if ( wahltemp>0 && wahltemp<8 ) wahl = wahltemp; } } } // DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG // DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG // DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG // DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG // DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG // DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG // DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG // DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG _bDebug=false; // nur zum TEST, Anzeige der Dateizeilen if (Pid == ROOT) { // laden der Datei // Testausgabe // Dateiladen if ( readFile(wahl)!=0) { printf("Fehler beim Öffnen bzw. Lesen der Datei"); MPI_Finalize(); return 1; } // Testausgabe testPrintRoot(0); } // Senden der Spalten und Zeilen // hier fehlt Code, Plausibilitätsprüfungen // Variablen int prev; int next; MPI_Status status; // Struktur char* Lokal_Top=NULL; char* Lokal_Bottom=NULL; char* _Lokal_zellen_Neu=NULL; // Irgendetwas allokieren prev=0; // koennte richtig sein next=0; int anz=500; // maximal 500 mal berechnen anz=1; // erstmal eine Schleife for (int iLoop=0; iLoop