Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <mpi.h>
- #include <stdio.h>
- int main(int argc, char** argv) {
- // Initialize the MPI environment
- MPI_Init(NULL, NULL);
- //
- // // Get the number of processes
- int world_size;
- MPI_Comm_size(MPI_COMM_WORLD, &world_size);
- // Get the rank of the process
- int world_rank;
- MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
- // Get the name of the processor
- char processor_name[MPI_MAX_PROCESSOR_NAME];
- int name_len;
- MPI_Get_processor_name(processor_name, &name_len);
- // // Print off a hello world message
- printf("Hello world from processor %s, rank %d" " out of %d processors\n", processor_name, world_rank, world_size);
- // Finalize the MPI environment.
- MPI_Finalize();
- }
- #include "mpi.h"
- #include <stdio.h>
- int main(int argc, char **argv) {
- int my_rank;
- int partner;
- int size, i,t;
- char greeting[100];
- MPI_Status stat;
- MPI_Init(&argc, &argv); /*START MPI */
- MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); /*DETERMINE RANK OF THIS PROCESSOR*/
- MPI_Comm_size(MPI_COMM_WORLD, &size); /*DETERMINE TOTAL NUMBER OF PROCESSORS*/
- sprintf(greeting, "Hello world: processor %d of %d\n", my_rank, size);
- if (my_rank ==0) {
- fputs(greeting, stdout);
- for (partner = 1; partner < size; partner++){
- MPI_Recv(greeting, sizeof(greeting), MPI_BYTE, partner, 1, MPI_COMM_WORLD, &stat);
- fputs (greeting, stdout);
- }
- }
- else {
- MPI_Send(greeting, strlen(greeting)+1, MPI_BYTE, 0,1,MPI_COMM_WORLD);
- }
- if (my_rank == 0) printf("That is all for now!\n");
- MPI_Finalize(); /* EXIT MPI */
- }
- #include "mpi.h"
- #include <stdio.h>
- int main(int argc, char *argv[])
- {
- int myid, numprocs, left, right;
- int buffer[10], buffer2[10];
- MPI_Request request, request2;
- MPI_Status status;
- MPI_Init(&argc,&argv);
- MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
- MPI_Comm_rank(MPI_COMM_WORLD, &myid);
- right = (myid + 1) % numprocs;
- left = myid - 1;
- if (left < 0)
- left = numprocs - 1;
- MPI_Irecv(buffer, 10, MPI_INT, left, 123, MPI_COMM_WORLD, &request);
- MPI_Isend(buffer2, 10, MPI_INT, right, 123, MPI_COMM_WORLD, &request2);
- MPI_Wait(&request, &status);
- MPI_Wait(&request2, &status);
- MPI_Finalize();
- return 0;
- }
- ~
- MOJE MOJE MOJE MOJE MOJE ____
- ______________________________________________________
- distribuirani sustavi
- korisnik@ODJ-O366-114:~$ ssh student20@172.16.55.121 -p 22
- student20@172.16.55.121's password:
- Last login: Fri Oct 13 14:36:23 2017 from 172.16.55.1
- [student20@bura3 ~]$ uname -a
- Linux bura3 2.6.32-642.1.1.el6.x86_64 #1 SMP Fri May 6 14:54:05 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux
- #!/bin/bash -l
- #PBS -l
- select=5:ncpus=24:mem=4gb
- #PBS -l walltime=00:10:00 naredba se vrti 10min i onda se prekida
- #PBS -q workq default nešto
- #PBS -N
- izracun_br1
- cd $PBS_O_WORKDIR
- -mpirun -np 48 .......... pokrećemo proces (48 procesa)
- -machinefile ............ zadani host file - opcija
- -u emacsu upišemo
- emacs -nw mpi.pbs
- -izlazimo iz emacsa crtl-x -c .... za save
- #PBS -l select=2:ncozs=24:mem=4GB
- #PBS -l walltime=00:10:00
- #PBS -l place=scatter:excl
- #PBS -q workq
- #PBS -v
- echo $PBS_NODEFILE
- cd $PBS_O_WORKDIR
- mpirun -np 48 -machinefile $PBS_NODEFILE hello_world
- #mpirun -np 48 -machinefile $PBS_NODEFILE send_rec
- mpirun -np 48 -machinefile $PBS_NODEFILE isend_irec
- #mpirun -np 48 -machinefile $PBS_NODEFILE barrier
- -u emacsu upišemo
- emacs -nw hello_world.c
- -izlazimo iz emacsa crtl-x-c za save
- -za stvaranje direktorija
- mkdir vjezbe1
- -za šetanje
- cd ./vjezbe1 (može radit i bez ./)
- -u emacsu smo upisali
- #include <mpi.h>
- #include <stdio.h>
- int main(int argc, char** argv){
- //Initializr the MPI enviroment
- MPI_Init(NULL,NULL);
- //Get the number of processes
- int world_size;
- MPI_Comm_size(MPI_COMM_WORLD,&world_size);
- //Get the rank of processes
- int world_rank;
- MPI_Comm_rank(MPI_COMM_WORLD,&world_rank);
- //Get the name of processor
- char processor_name[MPI_MAX_PROCESSOR_NAME];
- int name_len;
- MPI_Get_processor_name(processor_name,&name_len);
- //print off a hello world message
- printf("Hello world from processor %s, rank %d" " out of %d processors\n" , p\
- rocessor_name, world_rank, world_size);
- //Finalize the MPI enviroment
- MPI_Finalize();
- }
- -tada kompaliramo progrma
- [student20@bura3 ~]$ mpicc hello_world.c
- -kompalirani file s završnim kodom a.out (automatski se generira kod komp)
- [student20@bura3 ~]$ ls
- a.out hello_world.c mpi.pbs
- -za provjeru tog file (a.out)
- [student20@bura3 ~]$ file a.out
- a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
- [student20@bura3 ~]$
- -umjesto a.out možemo promjenit ime u hello_world
- [student20@bura3 ~]$ mpicc -o hello_world hello_world.c
- -pokretanje programa
- [student20@bura3 ~]$ ./a.out
- Hello world from processor bura3, rank 0 out of 1 processors
- ILI
- [student20@bura3 ~]$ ./hello_world
- Hello world from processor bura3, rank 0 out of 1 processors
- -nešto napraviti
- vi mpi.pbi
- -izlazi iz vi sa spremanjem
- :wq!
- -sprintf (slično kao printf ,samo formatizirano)
- 2.ZADATAK
- -u novom file pišemo
- emacs -nw send_rec.c
- -ovo
- #include "mpi.h"
- #include <stdio.h>
- int main(int argc,char **argv){
- int my_rank;
- int partner;
- int size,i,t;
- char greeting[100];
- MPI_Status stat;
- MPI_Init(&argc,&argv); /*Start MPI*/
- MPI_Comm_rank(MPI_COMM_WORLD,&my_rank); /*Determine rank of this processor*/
- MPI_Comm_size(MPI_COMM_WORL,&size); /*Determine total number of procesors */
- sprintf(greeting, "Hello world : processor %d of %d\n", my_rank,size);
- if(my_rank==0){
- fputs(greeting, stdout);
- for(partner = 1; partner < size; partner++){
- MPI_Recv(greeting,sizeof(greeting),MPI_BYTE,partner,1,MPI_COMM_WORLD,&stat);
- fputs(greeting,stdout);
- }
- }
- else{
- MPI_Send(greeting,strlen(greeting)+1,MPI_BYTE,0,1,MPI_COMM_WORLD);
- }
- }
- -kompaliranje programa
- [student20@bura3 ~]$ mpicc send_rec.c
- send_rec.c: In function ‘main’:
- send_rec.c:27: warning: incompatible implicit declaration of built-in function ‘strlen’
- -i pokretanje programa (sa -np 2 određujemo broj procesa ... kod ovog primjera "2")
- [student20@bura3 ~]$ mpirun -np 2 ./a.out
- Hello world : processor 0 of 2
- Hello world : processor 1 of 2
- That is all for now
- ILI s 8 procesa
- [student20@bura3 ~]$ mpirun -np 8 ./a.out
- Hello world : processor 0 of 8
- Hello world : processor 1 of 8
- Hello world : processor 2 of 8
- Hello world : processor 3 of 8
- Hello world : processor 4 of 8
- Hello world : processor 5 of 8
- Hello world : processor 6 of 8
- Hello world : processor 7 of 8
- That is all for now
- 3.ZADATAK
- -ponovo pokrećemo emacs -nw isend_rec.c
- #include "mpi.h"
- #include <stdio.h>
- int main(int argc,char *argv[])
- {
- int myid, numprocs,left,right;
- int buffer[10], buffer2[10];
- MPI_Request request,request2;
- MPI_Status status;
- MPI_Init(&argc,&argv);
- MPI_Comm_rank(MPI_COMM_WORLD,&myid); /*Determine rank of this processor*/
- MPI_Comm_size(MPI_COMM_WORL,&numprocs); /*Determine total number of procesors */
- right=(myid+1)%numprocs;
- left=myid-1;
- if(left<0)
- left=numprocs-1;
- MPI_Irecv(buffer,10,MPI_INT,left,123,MPI_COMM_WORLD,&request);
- MPI_Isend(buffer2,10,MPI_INT,right,123,MPI_COMM_WORLD,&request2);
- MPI_Wait(&request,&status);
- MPI_Wait(&request2,&status);
- MPI_Finalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement