Skip to main content
Homepage
Explore
Search or go to…
/
Sign in
Explore
Primary navigation
Project
O
OpenMPI_2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Collapse sidebar
Snippets
Groups
Projects
Show more breadcrumbs
Cliff
OpenMPI_2
Commits
205799e6
Commit
205799e6
authored
Feb 12, 2016
by
13513044
Browse files
Options
Downloads
Patches
Plain Diff
dikit lagi
parent
4388a23b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.swp
+0
-0
0 additions, 0 deletions
.swp
bucketsort
+0
-0
0 additions, 0 deletions
bucketsort
bucketsort.c
+149
-0
149 additions, 0 deletions
bucketsort.c
mpi_hostfile
+2
-1
2 additions, 1 deletion
mpi_hostfile
with
151 additions
and
1 deletion
.swp
+
0
−
0
View file @
205799e6
No preview for this file type
This diff is collapsed.
Click to expand it.
bucketsort
0 → 100755
+
0
−
0
View file @
205799e6
File added
This diff is collapsed.
Click to expand it.
bucketsort.c
0 → 100644
+
149
−
0
View file @
205799e6
#include
"mpi.h"
#include
<stdio.h>
#include
<string.h>
#include
<stdlib.h>
#include
<time.h>
#include
<assert.h>
int
main
(
int
argc
,
char
*
argv
[]
)
{
double
starttime
,
endtime
;
int
t
,
i
,
j
,
c
,
d
;
int
proceso_id
;
char
processor_name
[
MPI_MAX_PROCESSOR_NAME
];
int
namelen
;
int
numprocsused
;
// Intiating parallel part
MPI_Status
stat
;
MPI_Init
(
NULL
,
NULL
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
numprocsused
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
proceso_id
);
MPI_Get_processor_name
(
processor_name
,
&
namelen
);
unsigned
int
receivedElement
;
if
(
proceso_id
==
0
)
{
// if it is main process
int
size
;
scanf
(
"%d"
,
&
size
);
unsigned
int
*
array
=
malloc
(
sizeof
(
unsigned
int
)
*
size
);
for
(
i
=
0
;
i
<
size
;
i
++
)
array
[
i
]
=
rand
()
%
size
;
// starting time calculation of the sort
starttime
=
MPI_Wtime
();
// min and max values are got
unsigned
int
min
=
array
[
0
];
unsigned
int
max
=
array
[
0
];
for
(
i
=
0
;
i
<
size
;
i
++
)
{
if
(
array
[
i
]
<
min
)
{
min
=
array
[
i
];
}
if
(
array
[
i
]
>
max
)
{
max
=
array
[
i
];
}
}
// calculating how many numbers each bucket/process will get numbers
int
*
elementQtyArray
=
malloc
(
sizeof
(
int
)
*
numprocsused
);
// default values
for
(
d
=
1
;
d
<
numprocsused
;
d
++
)
{
elementQtyArray
[
d
]
=
0
;
}
int
pridetas
;
for
(
d
=
0
;
d
<
size
;
d
++
)
{
int
increaseOf
=
max
/
(
numprocsused
-
1
);
int
iteration
=
1
;
pridetas
=
0
;
for
(
j
=
increaseOf
;
j
<=
max
;
j
=
j
+
increaseOf
)
{
if
(
array
[
d
]
<=
j
)
{
elementQtyArray
[
iteration
]
++
;
pridetas
=
1
;
break
;
}
iteration
++
;
}
if
(
!
pridetas
)
elementQtyArray
[
iteration
-
1
]
++
;
}
for
(
i
=
1
;
i
<
numprocsused
;
i
++
)
{
MPI_Send
(
&
elementQtyArray
[
i
],
1
,
MPI_INT
,
i
,
0
,
MPI_COMM_WORLD
);
}
// doing the same, this time sending the numbers
for
(
d
=
0
;
d
<
size
;
d
++
)
{
int
increaseOf
=
max
/
(
numprocsused
-
1
);
int
iteration
=
1
;
int
issiunte
=
0
;
for
(
j
=
increaseOf
;
j
<=
max
;
j
=
j
+
increaseOf
)
{
if
(
array
[
d
]
<=
j
)
{
MPI_Send
(
&
array
[
d
],
1
,
MPI_UNSIGNED
,
iteration
,
1
,
MPI_COMM_WORLD
);
issiunte
=
1
;
break
;
}
iteration
++
;
}
if
(
!
issiunte
)
{
MPI_Send
(
&
array
[
d
],
1
,
MPI_UNSIGNED
,
iteration
-
1
,
1
,
MPI_COMM_WORLD
);
}
}
// Getting back results and adding them to one array
int
lastIndex
=
0
;
int
indexi
=
0
;
for
(
i
=
1
;
i
<
numprocsused
;
i
++
)
{
unsigned
int
*
recvArray
=
malloc
(
sizeof
(
unsigned
int
)
*
elementQtyArray
[
i
]);
MPI_Recv
(
&
recvArray
[
0
],
elementQtyArray
[
i
],
MPI_UNSIGNED
,
i
,
2
,
MPI_COMM_WORLD
,
&
stat
);
if
(
lastIndex
==
0
)
{
lastIndex
=
elementQtyArray
[
i
];
}
for
(
j
=
0
;
j
<
elementQtyArray
[
i
];
j
++
)
{
array
[
indexi
]
=
recvArray
[
j
];
indexi
++
;
}
}
// stoping the time
endtime
=
MPI_Wtime
();
// showing results in file
for
(
c
=
0
;
c
<
size
;
c
++
)
{
printf
(
"%d
\n
"
,
array
[
c
]);
}
// sorting results
printf
(
"it took %f seconds
\n
"
,
endtime
-
starttime
);
printf
(
"Numbers: %d
\n
"
,
size
);
printf
(
"Processes: %d
\n
"
,
numprocsused
);
}
else
{
// if child process
int
elementQtyUsed
;
// kiek elementu si gija gauja is tevinio proceso
// --- getting the number of numbers in the bucket
MPI_Recv
(
&
elementQtyUsed
,
1
,
MPI_INT
,
0
,
0
,
MPI_COMM_WORLD
,
&
stat
);
unsigned
int
*
localArray
=
malloc
(
sizeof
(
unsigned
int
)
*
elementQtyUsed
);
// initiating a local bucket
int
li
;
// --- getting numbers from the main process
for
(
li
=
0
;
li
<
elementQtyUsed
;
li
++
)
{
MPI_Recv
(
&
receivedElement
,
1
,
MPI_UNSIGNED
,
0
,
1
,
MPI_COMM_WORLD
,
&
stat
);
localArray
[
li
]
=
receivedElement
;
}
// --- sorting the bucket
for
(
c
=
1
;
c
<=
elementQtyUsed
-
1
;
c
++
)
{
d
=
c
;
while
(
d
>
0
&&
localArray
[
d
]
<
localArray
[
d
-
1
])
{
t
=
localArray
[
d
];
localArray
[
d
]
=
localArray
[
d
-
1
];
localArray
[
d
-
1
]
=
t
;
d
--
;
}
}
// --- sending back sorted array
MPI_Send
(
localArray
,
elementQtyUsed
,
MPI_UNSIGNED
,
0
,
2
,
MPI_COMM_WORLD
);
}
MPI_Finalize
();
return
0
;
}
This diff is collapsed.
Click to expand it.
mpi_hostfile
+
2
−
1
View file @
205799e6
#daftar host
localhost
167.205.35.25
167.205.35.26
167.205.35.28
167.205.35.29
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment